Documentation
¶
Overview ¶
Package cache provides a generic key-value cache interface.
Index ¶
- type Cache
- type FilesystemCache
- func (c *FilesystemCache) Close() error
- func (c *FilesystemCache) Get(_ context.Context, key string) ([]byte, bool, error)
- func (c *FilesystemCache) GetMulti(ctx context.Context, keys []string) (map[string][]byte, error)
- func (c *FilesystemCache) Set(_ context.Context, key string, value []byte) error
- func (c *FilesystemCache) SetMulti(ctx context.Context, entries map[string][]byte) error
- type InMemoryCache
- func (c *InMemoryCache) Close() error
- func (c *InMemoryCache) Get(_ context.Context, key string) ([]byte, bool, error)
- func (c *InMemoryCache) GetMulti(_ context.Context, keys []string) (map[string][]byte, error)
- func (c *InMemoryCache) Set(_ context.Context, key string, value []byte) error
- func (c *InMemoryCache) SetMulti(_ context.Context, entries map[string][]byte) error
- type RedisCache
- func (c *RedisCache) Close() error
- func (c *RedisCache) Get(ctx context.Context, key string) ([]byte, bool, error)
- func (c *RedisCache) GetMulti(ctx context.Context, keys []string) (map[string][]byte, error)
- func (c *RedisCache) Set(ctx context.Context, key string, value []byte) error
- func (c *RedisCache) SetMulti(ctx context.Context, entries map[string][]byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
// Get retrieves a value by key. Returns the value, whether it was found, and any error.
Get(ctx context.Context, key string) ([]byte, bool, error)
// Set stores a value by key.
Set(ctx context.Context, key string, value []byte) error
// GetMulti retrieves multiple values by keys. Returns a map of found key-value pairs.
GetMulti(ctx context.Context, keys []string) (map[string][]byte, error)
// SetMulti stores multiple key-value pairs.
SetMulti(ctx context.Context, entries map[string][]byte) error
// Close releases resources held by the cache.
Close() error
}
Cache is a generic key-value cache.
type FilesystemCache ¶ added in v0.16.0
type FilesystemCache struct {
// contains filtered or unexported fields
}
FilesystemCache is a key-value cache backed by files in a directory. Keys are SHA256-hashed to produce safe filenames.
func NewFilesystem ¶ added in v0.16.0
func NewFilesystem(dir string) (*FilesystemCache, error)
NewFilesystem creates a new filesystem-backed cache in the given directory. The directory is created if it does not exist.
func (*FilesystemCache) Close ¶ added in v0.16.0
func (c *FilesystemCache) Close() error
Close is a no-op for the filesystem cache.
type InMemoryCache ¶
type InMemoryCache struct {
// contains filtered or unexported fields
}
InMemoryCache is a thread-safe in-memory cache backed by a map.
func NewInMemory ¶
func NewInMemory(ttl time.Duration) *InMemoryCache
NewInMemory creates a new in-memory cache. A zero TTL means entries never expire.
func (*InMemoryCache) Close ¶
func (c *InMemoryCache) Close() error
Close is a no-op for the in-memory cache.
func (*InMemoryCache) GetMulti ¶
GetMulti retrieves multiple values by keys, skipping expired entries.
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache is a cache backed by Redis.
func NewRedis ¶
func NewRedis(redisURL, prefix string, ttl time.Duration) (*RedisCache, error)
NewRedis creates a new Redis-backed cache. The prefix is prepended to all keys (e.g., "panda:embed:"). A zero TTL means entries never expire.
func (*RedisCache) Close ¶
func (c *RedisCache) Close() error
Close closes the Redis client connection.