cache

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

type Cache interface {
	Get(ctx context.Context, key string) ([]byte, error)
	Set(ctx context.Context, key string, value []byte, expiration time.Duration) error
	Delete(ctx context.Context, key string) error
	Exists(ctx context.Context, key string) (bool, error)
	Clear(ctx context.Context) error
	GetWithTTL(ctx context.Context, key string) ([]byte, time.Duration, error)
	SetJSON(ctx context.Context, key string, value interface{}, expiration time.Duration) error
	GetJSON(ctx context.Context, key string, dest interface{}) error
}

Cache interface defines caching operations

type CacheItem

type CacheItem struct {
	Value      []byte
	Expiration time.Time
	CreatedAt  time.Time
}

CacheItem represents a cached item

type CacheManager

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

CacheManager manages multiple cache instances

func NewCacheManager

func NewCacheManager() *CacheManager

NewCacheManager creates a new cache manager

func (*CacheManager) AddCache

func (m *CacheManager) AddCache(name string, cache Cache)

AddCache adds a cache instance

func (*CacheManager) GetCache

func (m *CacheManager) GetCache(name string) (Cache, error)

GetCache retrieves a cache instance

func (*CacheManager) GetDefaultCache

func (m *CacheManager) GetDefaultCache() Cache

GetDefaultCache returns the default cache instance

type MemoryCache

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

MemoryCache implements an in-memory cache

func NewMemoryCache

func NewMemoryCache(maxTTL time.Duration) *MemoryCache

NewMemoryCache creates a new in-memory cache

func (*MemoryCache) Clear

func (c *MemoryCache) Clear(ctx context.Context) error

Clear removes all values from memory cache

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(ctx context.Context, key string) error

Delete removes a value from memory cache

func (*MemoryCache) Exists

func (c *MemoryCache) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists in memory cache

func (*MemoryCache) Get

func (c *MemoryCache) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves a value from memory cache

func (*MemoryCache) GetJSON

func (c *MemoryCache) GetJSON(ctx context.Context, key string, dest interface{}) error

GetJSON retrieves and decodes a JSON value

func (*MemoryCache) GetWithTTL

func (c *MemoryCache) GetWithTTL(ctx context.Context, key string) ([]byte, time.Duration, error)

GetWithTTL retrieves a value with remaining TTL

func (*MemoryCache) Set

func (c *MemoryCache) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error

Set stores a value in memory cache

func (*MemoryCache) SetJSON

func (c *MemoryCache) SetJSON(ctx context.Context, key string, value interface{}, expiration time.Duration) error

SetJSON stores a JSON-encoded value

type RedisCache

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

RedisCache implements Redis-based cache

func NewRedisCache

func NewRedisCache(addr, password string, db int, prefix string) *RedisCache

NewRedisCache creates a new Redis cache

func (*RedisCache) Clear

func (c *RedisCache) Clear(ctx context.Context) error

Clear removes all values from Redis cache with the prefix

func (*RedisCache) Delete

func (c *RedisCache) Delete(ctx context.Context, key string) error

Delete removes a value from Redis cache

func (*RedisCache) Exists

func (c *RedisCache) Exists(ctx context.Context, key string) (bool, error)

Exists checks if a key exists in Redis cache

func (*RedisCache) Get

func (c *RedisCache) Get(ctx context.Context, key string) ([]byte, error)

Get retrieves a value from Redis cache

func (*RedisCache) GetJSON

func (c *RedisCache) GetJSON(ctx context.Context, key string, dest interface{}) error

GetJSON retrieves and decodes a JSON value from Redis

func (*RedisCache) GetWithTTL

func (c *RedisCache) GetWithTTL(ctx context.Context, key string) ([]byte, time.Duration, error)

GetWithTTL retrieves a value with remaining TTL from Redis

func (*RedisCache) Set

func (c *RedisCache) Set(ctx context.Context, key string, value []byte, expiration time.Duration) error

Set stores a value in Redis cache

func (*RedisCache) SetJSON

func (c *RedisCache) SetJSON(ctx context.Context, key string, value interface{}, expiration time.Duration) error

SetJSON stores a JSON-encoded value in Redis

Jump to

Keyboard shortcuts

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