cache

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// Operation Get
	ErrGetCacheMiss = errors.New("cache miss")
)

Functions

This section is empty.

Types

type Cache

type Cache struct {
	RedisClient         *redis.Client
	Tracer              adapter.Tracer
	Logger              adapter.Logger
	Semaphore           adapter.Semaphore
	KeyPrefix           string
	KeyGenerator        key.KeyGeneratorFunc
	KeyVersionGenerator key.KeyGeneratorFunc
	VersionGenerator    key.KeyGeneratorFunc
	VersionExpire       time.Duration
	LockGenerator       key.KeyGeneratorFunc
	LockDuration        time.Duration
	LockInterval        time.Duration
	ExpireDefault       time.Duration
	// contains filtered or unexported fields
}

Cache is the internal cache implementation.

func NewCache

func NewCache(redisClient *redis.Client, opts Options) (*Cache, error)

NewCache creates a new cache instance with options.

func (*Cache) Cached

func (c *Cache) Cached(
	keyName string,
	ttl interface{},
	versioning bool,
	prefix string,
) func(
	fn func(ctx context.Context, args ...interface{}) (interface{}, error),
	customKeyFunc key.CustomKeyFunction,
) func(resultType interface{}, ctx context.Context, args ...interface{}) (interface{}, error)

func (*Cache) CleanCache

func (c *Cache) CleanCache(
	ctx context.Context,
	key string,
	params map[string]interface{},
	session redis.Pipeliner,
	execute bool,
	listLockedKey *[]string,
) error

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string, resultType interface{}) error

Get retrieves a value from cache by key and deserializes it into resultType. Returns an error if the key doesn't exist or if deserialization fails.

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, value interface{}, ttl time.Duration) error

Set stores a value in cache with the specified TTL. The value will be serialized before storing.

type Options

type Options struct {
	KeyPrefix           string
	ExpireDefault       time.Duration
	VersionExpire       time.Duration
	LockDuration        time.Duration
	LockInterval        time.Duration
	Tracer              adapter.Tracer
	Logger              adapter.Logger
	Semaphore           adapter.Semaphore
	KeyGenerator        key.KeyGeneratorFunc
	KeyVersionGenerator key.KeyGeneratorFunc
	VersionGenerator    key.KeyGeneratorFunc
	LockGenerator       key.KeyGeneratorFunc
}

Options holds all cache configuration.

Jump to

Keyboard shortcuts

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