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 ¶
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.