cache

package
v0.17.3 Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2023 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Cache package to provide an interface to interact with stores like BigCache and Redis.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheIsDisabled = errors.New("Cache is disabled")
)

Functions

This section is empty.

Types

type BigCacheClient

type BigCacheClient interface {
	Get(key string) ([]byte, error)
	Set(key string, entry []byte) error
	Delete(key string) error
	Reset() error
}

type BigCacheStore

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

func (*BigCacheStore) Clear

func (s *BigCacheStore) Clear() error

func (*BigCacheStore) Delete

func (s *BigCacheStore) Delete(key string) error

func (*BigCacheStore) Get

func (s *BigCacheStore) Get(key string) ([]byte, error)

func (*BigCacheStore) Set

func (s *BigCacheStore) Set(key string, value []byte, _ time.Duration) error

type Cache

type Cache struct {
	TTL       time.Duration
	StoreType CacheStoreType
	// contains filtered or unexported fields
}

func NewBigCache

func NewBigCache(ctx context.Context, config bigcache.Config) (*Cache, error)

Creates a new Cache using BigCache.

Requires a BigCache config that can be created with bigcache.DefaultConfig(n*time.Minute).

func NewRedis

func NewRedis(ctx context.Context, options *redis.Options, ttl time.Duration) (*Cache, error)

Creates a new Cache using go-redis.

func (*Cache) Clear

func (c *Cache) Clear() error

Clears the entire cache.

func (*Cache) Delete

func (c *Cache) Delete(key string) error

Deletes an item from the cache.

func (*Cache) Get

func (c *Cache) Get(key string) ([]byte, error)

Returns an item from the cache. If no item is found, returns nil for the item and error.

func (*Cache) Set

func (c *Cache) Set(key string, item []byte) error

Saves an item under the key provided.

type CacheStoreType added in v0.14.1

type CacheStoreType string
const (
	BigCache   CacheStoreType = "BigCache"
	RedisCache CacheStoreType = "Redis"
)

type RedisClient

type RedisClient interface {
	Get(ctx context.Context, key string) *redis.StringCmd
	Set(ctx context.Context, key string, value any, ttl time.Duration) *redis.StatusCmd
	Del(ctx context.Context, keys ...string) *redis.IntCmd
	FlushAll(ctx context.Context) *redis.StatusCmd
}

type RedisStore

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

func (*RedisStore) Clear

func (s *RedisStore) Clear() error

func (*RedisStore) Delete

func (s *RedisStore) Delete(key string) error

func (*RedisStore) Get

func (s *RedisStore) Get(key string) ([]byte, error)

func (*RedisStore) Set

func (s *RedisStore) Set(key string, value []byte, ttl time.Duration) error

type Store

type Store interface {
	Get(key string) ([]byte, error)
	Set(key string, value []byte, ttl time.Duration) error
	Delete(key string) error
	Clear() error
}

Jump to

Keyboard shortcuts

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