cache

package
v1.0.12 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DeleteFromCache

func DeleteFromCache(ctx context.Context, store *CacheStore, key string)

DeleteFromCache removes the entry associated with the specified key from the Redis cache. It accepts a CacheStore and a key string as parameters. If the deletion process encounters an error, it logs the error message along with the cache key.

func GetFromCache

func GetFromCache[T any](ctx context.Context, store *CacheStore, key string) (*T, bool)

GetFromCache retrieves a cached item from Redis by the specified key. It returns a pointer to the item of type T and a boolean indicating whether the item was found in the cache. If the item is not found or an error occurs during retrieval or unmarshalling, it logs an error and returns nil and false.

func SetToCache

func SetToCache[T any](ctx context.Context, store *CacheStore, key string, data *T, expiration time.Duration)

SetToCache stores the given data in the Redis cache using the specified key and expiration duration. It accepts a CacheStore, a key string, a pointer to the data to be cached, and the expiration time as parameters. The data is marshaled into JSON format before being set in the cache. If marshaling fails, an error is logged, and the function returns without storing the data. If setting the data in the cache fails, an error is logged; otherwise, a debug log indicates successful caching.

Types

type CacheStore

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

CacheStore represents a Redis cache store.

func NewCacheStore

func NewCacheStore(redis *redis.Client, logger logger.LoggerInterface) *CacheStore

NewCacheStore creates a new instance of CacheStore using the given context, Redis client, and logger.

Jump to

Keyboard shortcuts

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