Documentation
¶
Overview ¶
Package cache provides a thread-safe key-value interface for persisting data to disk. Ideal use case is for caching data that is expensive to compute in devtools and unlikely to change. Do NOT use it to store sensitive information.
Index ¶
- type Cache
- func (c *Cache) Close() error
- func (c *Cache) DeleteAll() error
- func (c *Cache) DeleteKey(subpath, key string) error
- func (c *Cache) DeleteSubpath(subpath string) error
- func (c *Cache) Keys(subpath string) (iter.Seq[string], error)
- func (c *Cache) Load(subpath, key string, dst any) (bool, error)
- func (c *Cache) Store(subpath, key string, data any) error
- type Option
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is an instance of persistence storage on disk. It provides methods for storing, loading, and removing encoded data on disk. It is safe to use concurrently. The Close method must be called when the cache is no longer needed.
func New ¶
New creates a new Cache, with its storage located at `path“ concatenated with `.ccc-cache/`. Example: New("./foo") returns a Cache instance that stores data at `./foo/.ccc-cache/`.
func (*Cache) DeleteAll ¶
DeleteAll removes all directories and file in the Cache. If the Cache is empty, DeleteAll returns nil (no error).
func (*Cache) DeleteKey ¶
DeleteKey deletes a file whose name matches the key at the given subpath. The subpath must exist. If the key does not exist, DeleteKey returns nil (no error).
func (*Cache) DeleteSubpath ¶
DeleteSubpath deletes a directory whose name matches the subpath. If the subpath does not exist, DeleteSubpath returns nil (no error).