cache

package
v2.2.0 Latest Latest
Warning

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

Go to latest
Published: May 17, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Cache package to provide an interface to interact with cache stores.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCacheIsDisabled = errors.New("cache is disabled")
	ErrRedisOptionsNil = errors.New("redis options is nil")
)

Functions

func GetCacheKey

func GetCacheKey(url string, authHeader string) (string, bool)

Returns the Cache key for the provided URL and a bool indicating if the key has an accessToken hash. Most of the time this will just return the URL.

Types

type BigCacheStore

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

func (BigCacheStore) Clear

func (s BigCacheStore) Clear(_ctx context.Context) error

func (BigCacheStore) Delete

func (s BigCacheStore) Delete(_ctx context.Context, key string) error

func (BigCacheStore) Get

func (s BigCacheStore) Get(_ctx context.Context, key string) ([]byte, error)

func (BigCacheStore) Set

func (s BigCacheStore) Set(_ctx context.Context, key string, value []byte) error

type Cache

type Cache struct {
	StoreType StoreType
	TTL       time.Duration
	// 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(ctx context.Context) error

func (*Cache) Delete

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

func (*Cache) Get

func (c *Cache) Get(ctx context.Context, key string) ([]byte, error)

func (*Cache) Set

func (c *Cache) Set(ctx context.Context, key string, item []byte) error

type RedisStore

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

func (RedisStore) Clear

func (s RedisStore) Clear(ctx context.Context) error

func (RedisStore) Delete

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

func (RedisStore) Get

func (s RedisStore) Get(ctx context.Context, key string) ([]byte, error)

func (RedisStore) Set

func (s RedisStore) Set(ctx context.Context, key string, value []byte) error

type Store

type Store interface {
	// Returns an item from the cache. If no item is found, returns nil for the item and error.
	Get(ctx context.Context, key string) ([]byte, error)

	// Saves an item under the key provided.
	Set(ctx context.Context, key string, value []byte) error

	// Deletes an item from the cache.
	Delete(ctx context.Context, key string) error

	// Clears the entire cache.
	//
	// For Redis, the entire 'cache' namespace under 'equinox' is deleted.
	Clear(ctx context.Context) error
}

type StoreType

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

Jump to

Keyboard shortcuts

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