Versions in this module Expand all Collapse all v0 v0.1.0 Feb 23, 2026 Changes in this version + const CompressionGzip + const CompressionNone + const CompressionSnappy + var ErrCorruptCompression = errors.New("cache: corrupt compressed payload") + var ErrDecryptFailed = errors.New("cache: decrypt failed") + var ErrEncryptValueTooBig = errors.New("cache: encrypt value too large") + var ErrEncryptionKey = errors.New("cache: encryption key must be 16, 24, or 32 bytes") + var ErrUnsupportedCodec = errors.New("cache: unsupported compression codec") + var ErrValueTooLarge = errors.New("cache: value exceeds max size") + func GetCtx[T any](ctx context.Context, cache *Cache, key string) (T, bool, error) + func GetJSONCtx[T any](ctx context.Context, cache *Cache, key string) (T, bool, error) + func GetJSON[T any](cache *Cache, key string) (T, bool, error) + func Get[T any](cache *Cache, key string) (T, bool, error) + func NewFileStore(ctx context.Context, dir string) cachecore.Store + func NewFileStoreWithConfig(ctx context.Context, cfg StoreConfig) cachecore.Store + func NewMemoStore(store cachecore.Store) cachecore.Store + func NewMemoryStore(ctx context.Context) cachecore.Store + func NewMemoryStoreWithConfig(ctx context.Context, cfg StoreConfig) cachecore.Store + func NewNullStore(ctx context.Context) cachecore.Store + func NewNullStoreWithConfig(ctx context.Context, cfg StoreConfig) cachecore.Store + func PullCtx[T any](ctx context.Context, cache *Cache, key string) (T, bool, error) + func Pull[T any](cache *Cache, key string) (T, bool, error) + func RefreshAheadCtx[T any](ctx context.Context, cache *Cache, key string, ttl, refreshAhead time.Duration, ...) (T, error) + func RefreshAheadValueWithCodec[T any](ctx context.Context, cache *Cache, key string, ttl, refreshAhead time.Duration, ...) (T, error) + func RefreshAhead[T any](cache *Cache, key string, ttl, refreshAhead time.Duration, ...) (T, error) + func RememberCtx[T any](ctx context.Context, cache *Cache, key string, ttl time.Duration, ...) (T, error) + func RememberStaleCtx[T any](ctx context.Context, cache *Cache, key string, ttl, staleTTL time.Duration, ...) (T, bool, error) + func RememberStale[T any](cache *Cache, key string, ttl, staleTTL time.Duration, fn func() (T, error)) (T, bool, error) + func Remember[T any](cache *Cache, key string, ttl time.Duration, fn func() (T, error)) (T, error) + func SetCtx[T any](ctx context.Context, cache *Cache, key string, value T, ttl time.Duration) error + func SetJSONCtx[T any](ctx context.Context, cache *Cache, key string, value T, ttl time.Duration) error + func SetJSON[T any](cache *Cache, key string, value T, ttl time.Duration) error + func Set[T any](cache *Cache, key string, value T, ttl time.Duration) error + type Cache struct + func NewCache(store cachecore.Store) *Cache + func NewCacheWithTTL(store cachecore.Store, defaultTTL time.Duration) *Cache + func (c *Cache) Add(key string, value []byte, ttl time.Duration) (bool, error) + func (c *Cache) AddCtx(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error) + func (c *Cache) BatchGetBytes(keys ...string) (map[string][]byte, error) + func (c *Cache) BatchGetBytesCtx(ctx context.Context, keys ...string) (map[string][]byte, error) + func (c *Cache) BatchSetBytes(values map[string][]byte, ttl time.Duration) error + func (c *Cache) BatchSetBytesCtx(ctx context.Context, values map[string][]byte, ttl time.Duration) error + func (c *Cache) Decrement(key string, delta int64, ttl time.Duration) (int64, error) + func (c *Cache) DecrementCtx(ctx context.Context, key string, delta int64, ttl time.Duration) (int64, error) + func (c *Cache) Delete(key string) error + func (c *Cache) DeleteCtx(ctx context.Context, key string) error + func (c *Cache) DeleteMany(keys ...string) error + func (c *Cache) DeleteManyCtx(ctx context.Context, keys ...string) error + func (c *Cache) Driver() cachecore.Driver + func (c *Cache) Flush() error + func (c *Cache) FlushCtx(ctx context.Context) error + func (c *Cache) GetBytes(key string) ([]byte, bool, error) + func (c *Cache) GetBytesCtx(ctx context.Context, key string) ([]byte, bool, error) + func (c *Cache) GetString(key string) (string, bool, error) + func (c *Cache) GetStringCtx(ctx context.Context, key string) (string, bool, error) + func (c *Cache) Increment(key string, delta int64, ttl time.Duration) (int64, error) + func (c *Cache) IncrementCtx(ctx context.Context, key string, delta int64, ttl time.Duration) (int64, error) + func (c *Cache) Lock(key string, ttl, timeout time.Duration) (bool, error) + func (c *Cache) LockCtx(ctx context.Context, key string, ttl, retryInterval time.Duration) (bool, error) + func (c *Cache) NewLockHandle(key string, ttl time.Duration) *LockHandle + func (c *Cache) PullBytes(key string) ([]byte, bool, error) + func (c *Cache) PullBytesCtx(ctx context.Context, key string) ([]byte, bool, error) + func (c *Cache) RateLimit(key string, limit int64, window time.Duration) (RateLimitStatus, error) + func (c *Cache) RateLimitCtx(ctx context.Context, key string, limit int64, window time.Duration) (RateLimitStatus, error) + func (c *Cache) RefreshAheadBytes(key string, ttl, refreshAhead time.Duration, fn func() ([]byte, error)) ([]byte, error) + func (c *Cache) RefreshAheadBytesCtx(ctx context.Context, key string, ttl, refreshAhead time.Duration, ...) ([]byte, error) + func (c *Cache) RememberBytes(key string, ttl time.Duration, fn func() ([]byte, error)) ([]byte, error) + func (c *Cache) RememberBytesCtx(ctx context.Context, key string, ttl time.Duration, ...) ([]byte, error) + func (c *Cache) RememberStaleBytes(key string, ttl, staleTTL time.Duration, fn func() ([]byte, error)) ([]byte, bool, error) + func (c *Cache) RememberStaleBytesCtx(ctx context.Context, key string, ttl, staleTTL time.Duration, ...) ([]byte, bool, error) + func (c *Cache) SetBytes(key string, value []byte, ttl time.Duration) error + func (c *Cache) SetBytesCtx(ctx context.Context, key string, value []byte, ttl time.Duration) error + func (c *Cache) SetString(key string, value string, ttl time.Duration) error + func (c *Cache) SetStringCtx(ctx context.Context, key string, value string, ttl time.Duration) error + func (c *Cache) Store() cachecore.Store + func (c *Cache) TryLock(key string, ttl time.Duration) (bool, error) + func (c *Cache) TryLockCtx(ctx context.Context, key string, ttl time.Duration) (bool, error) + func (c *Cache) Unlock(key string) error + func (c *Cache) UnlockCtx(ctx context.Context, key string) error + func (c *Cache) WithObserver(o Observer) *Cache + type CacheAPI interface + type CompressionCodec = cachecore.CompressionCodec + type CoreAPI interface + Driver func() cachecore.Driver + type CounterAPI interface + Decrement func(key string, delta int64, ttl time.Duration) (int64, error) + DecrementCtx func(ctx context.Context, key string, delta int64, ttl time.Duration) (int64, error) + Increment func(key string, delta int64, ttl time.Duration) (int64, error) + IncrementCtx func(ctx context.Context, key string, delta int64, ttl time.Duration) (int64, error) + type LockAPI interface + Lock func(key string, ttl, timeout time.Duration) (bool, error) + LockCtx func(ctx context.Context, key string, ttl, retryInterval time.Duration) (bool, error) + TryLock func(key string, ttl time.Duration) (bool, error) + TryLockCtx func(ctx context.Context, key string, ttl time.Duration) (bool, error) + Unlock func(key string) error + UnlockCtx func(ctx context.Context, key string) error + type LockHandle struct + func (l *LockHandle) Acquire() (bool, error) + func (l *LockHandle) AcquireCtx(ctx context.Context) (bool, error) + func (l *LockHandle) Block(timeout, retryInterval time.Duration, fn func() error) (bool, error) + func (l *LockHandle) BlockCtx(ctx context.Context, retryInterval time.Duration, ...) (bool, error) + func (l *LockHandle) Get(fn func() error) (bool, error) + func (l *LockHandle) GetCtx(ctx context.Context, fn func(context.Context) error) (bool, error) + func (l *LockHandle) Release() error + func (l *LockHandle) ReleaseCtx(ctx context.Context) error + type Observer interface + OnCacheOp func(ctx context.Context, op string, key string, hit bool, err error, ...) + type ObserverFunc func(ctx context.Context, op string, key string, hit bool, err error, ...) + func (f ObserverFunc) OnCacheOp(ctx context.Context, op string, key string, hit bool, err error, ...) + type RateLimitAPI interface + RateLimit func(key string, limit int64, window time.Duration) (RateLimitStatus, error) + RateLimitCtx func(ctx context.Context, key string, limit int64, window time.Duration) (RateLimitStatus, error) + type RateLimitStatus struct + Allowed bool + Count int64 + Remaining int64 + ResetAt time.Time + type ReadAPI interface + BatchGetBytes func(keys ...string) (map[string][]byte, error) + BatchGetBytesCtx func(ctx context.Context, keys ...string) (map[string][]byte, error) + GetBytes func(key string) ([]byte, bool, error) + GetBytesCtx func(ctx context.Context, key string) ([]byte, bool, error) + GetString func(key string) (string, bool, error) + GetStringCtx func(ctx context.Context, key string) (string, bool, error) + PullBytes func(key string) ([]byte, bool, error) + PullBytesCtx func(ctx context.Context, key string) ([]byte, bool, error) + type RefreshAheadAPI interface + RefreshAheadBytes func(key string, ttl, refreshAhead time.Duration, fn func() ([]byte, error)) ([]byte, error) + RefreshAheadBytesCtx func(ctx context.Context, key string, ttl, refreshAhead time.Duration, ...) ([]byte, error) + type RememberAPI interface + RememberBytes func(key string, ttl time.Duration, fn func() ([]byte, error)) ([]byte, error) + RememberBytesCtx func(ctx context.Context, key string, ttl time.Duration, ...) ([]byte, error) + RememberStaleBytes func(key string, ttl, staleTTL time.Duration, fn func() ([]byte, error)) ([]byte, bool, error) + RememberStaleBytesCtx func(ctx context.Context, key string, ttl, staleTTL time.Duration, ...) ([]byte, bool, error) + type StoreConfig struct + FileDir string + MemoryCleanupInterval time.Duration + type ValueCodec struct + Decode func([]byte) (T, error) + Encode func(T) ([]byte, error) + type WriteAPI interface + Add func(key string, value []byte, ttl time.Duration) (bool, error) + AddCtx func(ctx context.Context, key string, value []byte, ttl time.Duration) (bool, error) + BatchSetBytes func(values map[string][]byte, ttl time.Duration) error + BatchSetBytesCtx func(ctx context.Context, values map[string][]byte, ttl time.Duration) error + Delete func(key string) error + DeleteCtx func(ctx context.Context, key string) error + DeleteMany func(keys ...string) error + DeleteManyCtx func(ctx context.Context, keys ...string) error + Flush func() error + FlushCtx func(ctx context.Context) error + SetBytes func(key string, value []byte, ttl time.Duration) error + SetBytesCtx func(ctx context.Context, key string, value []byte, ttl time.Duration) error + SetString func(key string, value string, ttl time.Duration) error + SetStringCtx func(ctx context.Context, key string, value string, ttl time.Duration) error