cache

package
v2.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 11, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FileCache

type FileCache struct {
	Path string
}

FileCache is a cache backend that stores each key as a JSON file on disk.

func NewFileCache

func NewFileCache(path string) *FileCache

NewFileCache returns a file-based cache store.

func (*FileCache) Delete

func (c *FileCache) Delete(key string) error

func (*FileCache) Flush

func (c *FileCache) Flush() error

func (*FileCache) Get

func (c *FileCache) Get(key string) (string, error)

func (*FileCache) Set

func (c *FileCache) Set(key, value string, ttl time.Duration) error

type MemoryCache

type MemoryCache struct {
	// contains filtered or unexported fields
}

MemoryCache is an in-process cache backed by a map with TTL-based expiry.

func NewMemoryCache

func NewMemoryCache() *MemoryCache

NewMemoryCache returns an empty in-memory store.

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(key string) error

func (*MemoryCache) Flush

func (c *MemoryCache) Flush() error

func (*MemoryCache) Get

func (c *MemoryCache) Get(key string) (string, error)

func (*MemoryCache) Set

func (c *MemoryCache) Set(key, value string, ttl time.Duration) error

type RedisCache

type RedisCache struct {
	Client *redis.Client
}

RedisCache is a cache backend backed by Redis.

func NewRedisCache

func NewRedisCache(client *redis.Client) *RedisCache

NewRedisCache returns a Redis-backed cache store.

func (*RedisCache) Delete

func (c *RedisCache) Delete(key string) error

func (*RedisCache) Flush

func (c *RedisCache) Flush() error

func (*RedisCache) Get

func (c *RedisCache) Get(key string) (string, error)

func (*RedisCache) Set

func (c *RedisCache) Set(key, value string, ttl time.Duration) error

type Store

type Store interface {
	Get(key string) (string, error)
	Set(key string, value string, ttl time.Duration) error
	Delete(key string) error
	Flush() error
}

Store defines the cache contract.

func NewStore

func NewStore(driver, prefix string) (Store, error)

NewStore creates a cache Store for the given driver. If prefix is non-empty, all keys are automatically prefixed.

Supported drivers: "memory", "file", "redis". For "file": reads CACHE_FILE_PATH env (default: "storage/cache"). For "redis": reads REDIS_HOST, REDIS_PORT, REDIS_PASSWORD env.

Jump to

Keyboard shortcuts

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