cache

package
v1.0.50 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 20, 2026 License: MIT Imports: 8 Imported by: 0

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

View Source
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

func New() (*Cache, error)

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

func (c *Cache) Clear() error

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) GetDir

func (c *Cache) GetDir() string

GetDir returns the cache directory path.

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

type CachedDrive struct {
	ID   string `json:"id"`
	Name string `json:"name"`
}

CachedDrive represents a cached shared drive entry. Public so callers (drives.go) can populate it directly.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL