cache

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

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

Delete removes data by key from cache

func DeleteByStartsWith

func DeleteByStartsWith(ctx context.Context, rs *RedisStore, key string) error

DeleteByStartsWith removes data with key starting with provided key from cache

func Get

func Get[T any](ctx context.Context, rs *RedisStore, key string, val *T, fn func() (T, error), ttl time.Duration) error

Get gets value by key from cache. If key not present, runs fn and stores result in cache and returns result. If ttl == 0, default ttl is used.

Types

type KVMap

type KVMap[K comparable, V any] struct {
	// contains filtered or unexported fields
}

KVMap represents map with arbitrary key and value types

func NewKVMap

func NewKVMap[K comparable, V any](ttl time.Duration) *KVMap[K, V]

NewKVMap creates new map with arbitrary key and value types

func (*KVMap[K, V]) Get

func (m *KVMap[K, V]) Get(key K) (V, bool)

Get returns value by key

func (*KVMap[K, V]) Purge

func (m *KVMap[K, V]) Purge()

Purge - empties map data

func (*KVMap[K, V]) Set

func (m *KVMap[K, V]) Set(key K, val V)

Set sets value by key

func (*KVMap[K, V]) Size

func (m *KVMap[K, V]) Size() int

Size returns number of records

type RedisClient

type RedisClient interface {
	GetStruct(ctx context.Context, key string, value any) error
	SetStruct(ctx context.Context, key string, value any, ttl time.Duration) error
	DeleteByMatch(ctx context.Context, pattern string) error
	Delete(ctx context.Context, key string) error
}

RedisClient provides methods for working with redis

type RedisStore

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

RedisStore represents redis store

func NewRedisStore

func NewRedisStore(redisClient RedisClient, log *zap.Logger) *RedisStore

NewRedisStore creates new Cache instance

Directories

Path Synopsis
Package cache_mock is a generated GoMock package.
Package cache_mock is a generated GoMock package.

Jump to

Keyboard shortcuts

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