cache

package
v0.37.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache added in v0.36.0

type Cache[T Cacheable] interface {
	Set(ctx context.Context, key string, value T, ttl time.Duration) error
	Get(ctx context.Context, key string) (T, bool, error)
	Delete(ctx context.Context, key string) error
}

Cache is a generic cache interface for storing msgpack-serializable types T must have exported fields for proper serialization Examples: structs with exported fields, basic types (string, int, bool), slices, maps

func CreateCache added in v0.36.0

func CreateCache[T Cacheable](cacheCfg config.CacheCfg) Cache[T]

CreateCache creates a generic cache based on configuration T must be msgpack-serializable (structs with exported fields, basic types, etc.)

func NewGenericMemoryCache added in v0.36.0

func NewGenericMemoryCache[T Cacheable]() Cache[T]

NewGenericMemoryCache creates a new generic memory cache

func NewGenericRedisCache added in v0.36.0

func NewGenericRedisCache[T Cacheable](addresses []string, clientConfig map[string]string, cluster bool) Cache[T]

NewGenericRedisCache creates a new generic Redis cache using shared connection pool

type CacheCfg added in v0.24.1

type CacheCfg struct {
	MaxItemSize int64
	MinUseCount uint64
}

type Cacheable added in v0.36.0

type Cacheable interface {
	any
}

Cacheable represents types that can be cached Types must be msgpack-serializable (have exported fields or be basic types)

type GenericMemoryCache added in v0.36.0

type GenericMemoryCache[T Cacheable] struct {
	// contains filtered or unexported fields
}

GenericMemoryCache is a generic in-memory cache implementation

func (*GenericMemoryCache[T]) Delete added in v0.36.0

func (m *GenericMemoryCache[T]) Delete(ctx context.Context, key string) error

func (*GenericMemoryCache[T]) Get added in v0.36.0

func (m *GenericMemoryCache[T]) Get(ctx context.Context, key string) (T, bool, error)

func (*GenericMemoryCache[T]) Set added in v0.36.0

func (m *GenericMemoryCache[T]) Set(ctx context.Context, key string, value T, ttl time.Duration) error

type GenericRedisCache added in v0.36.0

type GenericRedisCache[T Cacheable] struct {
	// contains filtered or unexported fields
}

GenericRedisCache is a generic Redis cache implementation using msgpack serialization

func (*GenericRedisCache[T]) Delete added in v0.36.0

func (r *GenericRedisCache[T]) Delete(ctx context.Context, key string) error

func (*GenericRedisCache[T]) Get added in v0.36.0

func (r *GenericRedisCache[T]) Get(ctx context.Context, key string) (T, bool, error)

func (*GenericRedisCache[T]) Set added in v0.36.0

func (r *GenericRedisCache[T]) Set(ctx context.Context, key string, value T, ttl time.Duration) error

type MemoryCache

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

MemoryCache uses memory for cache purpose

func NewMemoryCache

func NewMemoryCache(maxSize int64) *MemoryCache

NewMemoryCache returns instance of memory cache

func (*MemoryCache) Delete

func (c *MemoryCache) Delete(obj *object.FileObject) error

Delete remove given response from cache

func (*MemoryCache) Get

Get returns a view of the cached response (zero-copy). The view shares the underlying buffer with the cached response, eliminating the need to copy the full response body on every cache hit.

func (*MemoryCache) Set

func (c *MemoryCache) Set(obj *object.FileObject, res *response.Response) error

Set put response to cache. Cache takes ownership of the response - no copying. The response must be buffered before caching. This eliminates one full copy compared to the previous implementation that copied on both Set and Get.

type RedisCache

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

RedisCache store response in redis

func NewRedis

func NewRedis(redisAddress []string, clientConfig map[string]string, cfg CacheCfg) *RedisCache

NewRedis create connection to redis and update it config from clientConfig map Uses shared connection pool to avoid duplicate Redis connections

func NewRedisCluster added in v0.15.0

func NewRedisCluster(redisAddress []string, clientConfig map[string]string, cfg CacheCfg) *RedisCache

func (*RedisCache) Delete

func (c *RedisCache) Delete(obj *object.FileObject) error

Delete remove response from cache

func (*RedisCache) Get

Get returns response from cache or error

func (*RedisCache) Set

func (c *RedisCache) Set(obj *object.FileObject, res *response.Response) error

Set put response into cache

type ResponseCache

type ResponseCache interface {
	Set(obj *object.FileObject, res *response.Response) error
	Get(obj *object.FileObject) (*response.Response, error)
	Delete(obj *object.FileObject) error
}

ResponseCache is interface for caching of mort responses

func Create

func Create(cacheCfg config.CacheCfg) ResponseCache

Create returns instance of Response cache for caching HTTP responses

Jump to

Keyboard shortcuts

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