cache

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Jul 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package cache provides a lightweight TTL-based disk cache for provider API responses. Each entry is a JSON file under ~/.ggvalet/cache/. Expired entries are pruned on read; flush with Cache.Flush().

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Key

func Key(host, path, params string) string

Key builds a canonical cache key from host + path + params.

Types

type Cache

type Cache struct {
	// contains filtered or unexported fields
}

Cache is a file-backed TTL store.

func New

func New(dir string) (*Cache, error)

New opens (or creates) the cache directory.

func (*Cache) Flush

func (c *Cache) Flush() int

Flush removes all files in the cache directory.

func (*Cache) Get

func (c *Cache) Get(key string) (json.RawMessage, bool)

Get returns raw cached bytes for key if live. Returns (nil, false) on miss or expiry.

func (*Cache) Set

func (c *Cache) Set(key string, v any, ttl time.Duration)

Set serialises v and stores it under key with the given TTL. Cache failures are silently dropped — they must never break the main path.

func (*Cache) Stats

func (c *Cache) Stats() (live, expired int)

Stats returns counts of live and expired entries without removing them.

func (*Cache) Unmarshal

func (c *Cache) Unmarshal(key string, dst any) bool

Unmarshal retrieves and deserialises cached data into dst. Returns false on miss, expiry, or unmarshal error.

Jump to

Keyboard shortcuts

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