cache

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2025 License: MIT Imports: 8 Imported by: 1

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

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

func New(path string, opts ...Option) (*Cache, error)

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) Close added in v0.0.3

func (c *Cache) Close() error

Close must be called when you are done using the cache

func (*Cache) DeleteAll

func (c *Cache) DeleteAll() error

DeleteAll removes all directories and file in the Cache. If the Cache is empty, DeleteAll returns nil (no error).

func (*Cache) DeleteKey

func (c *Cache) DeleteKey(subpath, key string) error

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

func (c *Cache) DeleteSubpath(subpath string) error

DeleteSubpath deletes a directory whose name matches the subpath. If the subpath does not exist, DeleteSubpath returns nil (no error).

func (*Cache) Keys

func (c *Cache) Keys(subpath string) (iter.Seq[string], error)

Keys returns an iterator over the file names in the given Cache subpath.

func (*Cache) Load

func (c *Cache) Load(subpath, key string, dst any) (bool, error)

Load reads data from path/subpath and stores in dst

func (*Cache) Store

func (c *Cache) Store(subpath, key string, data any) error

Store encodes given data and writes it to file at "/path/subpath/key"

type Option added in v0.0.3

type Option func(*Cache) *Cache

Option is a functional option for configuring the Cache.

func WithPermission added in v0.0.3

func WithPermission(perms uint32) Option

WithPermission configures the the unix permission bits on each file and directory within the Cache.

Jump to

Keyboard shortcuts

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