Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func SHA256KeyFunc ¶
SHA256KeyFunc hashes the key with SHA-256, producing a 64-char hex string.
func SafeNameKeyFunc ¶
SafeNameKeyFunc replaces filename-unsafe characters with underscores. Falls back to SHA256KeyFunc for keys longer than 200 characters.
Types ¶
type Cache ¶
type Cache[V any] struct { // contains filtered or unexported fields }
Cache is a generic, file-based, TTL-aware cache.
func (*Cache[V]) Clear ¶
Clear removes all files in this cache's directory. Only removes files, not subdirectories (which may be other namespaces).
func (*Cache[V]) Delete ¶
Delete removes a single cache entry. Returns nil if the entry does not exist.
func (*Cache[V]) Get ¶
Get returns the cached value. Returns (zero, false) if missing, expired, or unreadable. Expired entries are lazily deleted from disk.
type Codec ¶
type Codec interface {
Marshal(v any) ([]byte, error)
Unmarshal(data []byte, v any) error
Extension() string // must include leading dot: ".json", ".gob", etc.
}
Codec defines how cache entries are serialized and deserialized.
type Option ¶
type Option func(*config)
Option configures a Cache instance.
func WithDefaultTTL ¶
WithDefaultTTL sets the fallback TTL used when Set is called with ttl=0.
func WithKeyFunc ¶
WithKeyFunc sets the key-to-filename function. Default is SHA256KeyFunc.
func WithNamespace ¶
WithNamespace sets the subdirectory within the tool's cache directory.