Documentation
¶
Overview ¶
Package clicache pkg/clicache/clicache.go c4-vis-cli `skywire cli` commands use to memoize deployment-service fetches (SD `/api/services`, TPD `/all-transports`, UT `/uptimes`, etc.) for the CLI's --cfa minutes-old window.
Replaces the older per-URL JSON-file cache in `/tmp/<service>/...`, which had two problems:
- umask silently downgraded the intended 0o777/0o666 modes, so a CLI run as one user couldn't write into a dir created by a CLI run as another user (typically root via the visor service).
- Each cached endpoint was its own file on disk; no way to scope or evict in one operation.
The bbolt approach: one DB file at $XDG_CACHE_HOME/skywire/cli-fetch.db (default ~/.cache/skywire/cli-fetch.db). System-wide installs that want a shared cache across users can set SKYWIRE_CLI_CACHE_DB to /var/cache/skywire/cli-fetch.db (or similar) and ensure the file is 0o666 with a 0o777 parent — both are set explicitly by Open.
Entries are keyed by URL inside a per-service-host bucket so a future cache-clear can target a single service. Values are framed as JSON `{"body": "...", "fetched_at": "..."}` so a `bbolt dump` or `strings(1)` produces something legible.
Index ¶
Constants ¶
const DefaultFilename = "cli-fetch.db"
DefaultFilename is the bbolt file's basename under the cache dir.
Variables ¶
This section is empty.
Functions ¶
func DefaultPath ¶
DefaultPath returns the path the CLI should use for its cache db, resolved from (in order): $SKYWIRE_CLI_CACHE_DB, $XDG_CACHE_HOME/skywire/<DefaultFilename>, $HOME/.cache/skywire/<DefaultFilename>.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a thin wrapper around a bbolt.DB scoped to the CLI's service-fetch use case. The zero value is unusable — use Open.
func Open ¶
Open creates or opens the cache DB at path. The parent directory is created if missing. Both the directory and the DB file are explicitly chmodded to 0o777 / 0o666 so a root-owned DB remains writable by other users — this is what the older per-URL file cache failed to do (umask downgrade).
The wide permissions are deliberate: when the visor runs as root (e.g. via the systemd service) and the operator runs the CLI as their own user, both must be able to write the cache or the CLI degenerates back into per-user files. The cache contents are public deployment-service responses, so wide read perms aren't a disclosure risk. gosec G301/G302 warnings are silenced for the same reason.
A 2s open timeout matches the rest of the codebase's bbolt usage and prevents the CLI from hanging if another process holds the lock.
func (*Cache) Close ¶
Close releases the underlying bbolt DB. Safe to call on a nil receiver so callers can `defer c.Close()` without nil-checks.
func (*Cache) Fresh ¶
Fresh is a convenience wrapper that returns the entry only if it's been fetched within maxAge. Equivalent to Get + age check.