Documentation
¶
Overview ¶
Package cache wraps cli-common/cache for gro's Drive metadata cache.
Per cli-common/docs/working-with-state.md §4, gro's cache is disposable state at os.UserCacheDir()/google-readonly (via statedir.Cache). Writes are atomic via cli-common/cache's temp+rename envelope; TTL is hard-coded per resource (no user-configurable cache_ttl_hours — §4.4); reads classify a version/identity mismatch as a miss so schema bumps self-heal. The pre-B2b "<configdir>/cache/" relocation is retained for installs that pre-date the B2b cache move.
Index ¶
Constants ¶
const ( // DrivesFile is the cache file for shared drives. Retained as the legacy // pre-B2b file name so migrateLegacyCacheDir can find and relocate it. DrivesFile = "drives.json" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is gro's wrapper around the cli-common envelope cache.
func New ¶
New creates a new Cache instance rooted at the OS cache dir (B2b via cli-common/statedir). It also runs a transparent, best-effort one-time relocation of a pre-B2b cache that lived inside the config dir; relocation never fails New (the cache is disposable — it simply repopulates).
func (*Cache) Clear ¶
Clear removes all cached data for this instance. Scoped to <Root>/<InstanceKey> rather than the tool-level Root so a future move to a multi-instance Locator can't have one instance's Clear() silently evict every other instance's cache.
func (*Cache) DrivesStatus ¶ added in v1.0.56
DrivesStatus reports the freshness of the cached drives entry without fetching from the API. Returns (fetchedAt, ttl, status, now). A missing or corrupt envelope returns (time.Time{}, drivesTTL, StatusUninitialized, now); I/O errors propagate (in which case `status` is meaningless — callers MUST check err first). The TTL string is the hard-coded §4.4 value so the `refresh --status` table can render it without callers re-deriving it. `now` is the clock used for classification so callers can derive an Age column from the same instant — this matters in tests that swap nowFn.
func (*Cache) GetDrives ¶
func (c *Cache) GetDrives() ([]*CachedDrive, error)
GetDrives returns cached shared drives, or nil if cache is stale, missing, or corrupt. Corrupt-as-miss preserves the pre-MON-5371 behavior: caches are disposable, so a JSON parse error self-heals on the next API call. I/O errors (read failure, permission denied) propagate.
func (*Cache) SetDrives ¶
func (c *Cache) SetDrives(drives []*CachedDrive) error
SetDrives atomically writes the drives cache with the §4.4 hard-coded TTL.
type CachedDrive ¶
CachedDrive represents a cached shared drive entry. Public so callers (drives.go) can populate it directly.