cache

package
v0.0.0-...-cf68769 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CacheDummy configuration key
	CacheDummy = "dummy"
	// CacheInMemory configuration key
	CacheInMemory = "inmemory"
)
View Source
const (
	// CacheRedis configuration key
	CacheRedis = "redis"
)

Variables

This section is empty.

Functions

func InitCache

func InitCache(cfg *config.Config)

InitCache returns the currently active cache

Types

type Cache

type Cache interface {
	Contains(key string) bool
	Get(key string) interface{}
	Set(key string, value interface{})
	Clear()
}

Cache is a simple interface to interact with different cache mechanisms supported on thumbla

func GetCache

func GetCache() Cache

GetCache returns the currently active cache

type DummyCache

type DummyCache struct {
}

DummyCache provider an empty cache implementation that caches nothing!

func NewDummyCache

func NewDummyCache(cfg *config.Config) *DummyCache

NewDummyCache returns a new dummy cache that does nothing

func (*DummyCache) Clear

func (m *DummyCache) Clear()

Clear cleans the cache

func (*DummyCache) Contains

func (m *DummyCache) Contains(key string) bool

Contains checks if a key exists in the cache

func (*DummyCache) Get

func (m *DummyCache) Get(key string) interface{}

Get returns a cached item, if it exists, otherwise returns nil

func (*DummyCache) Set

func (m *DummyCache) Set(key string, value interface{})

Set saves an item into the cache

type InMemoryCache

type InMemoryCache struct {
	Cache *lru.LRU[string, interface{}]
}

InMemoryCache providers a generic in-memory LRU cache

func NewInMemoryCache

func NewInMemoryCache(cfg *config.Config) *InMemoryCache

NewInMemoryCache returns a new instance of the in-memory LRU based cache

func (*InMemoryCache) Clear

func (m *InMemoryCache) Clear()

Clear cleans the cache

func (*InMemoryCache) Contains

func (m *InMemoryCache) Contains(key string) bool

Contains checks if a key exists in the cache

func (*InMemoryCache) Get

func (m *InMemoryCache) Get(key string) interface{}

Get returns a cached item, if it exists, otherwise returns nil

func (*InMemoryCache) Set

func (m *InMemoryCache) Set(key string, value interface{})

Set saves an item into the cache

type RedisCache

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

RedisCache provides Redis-backed LRU cache implementation

func NewRedisCache

func NewRedisCache(cfg *config.Config) *RedisCache

NewRedisCache returns a new Redis cache instance

func (*RedisCache) Clear

func (r *RedisCache) Clear()

Clear removes all items from the Redis cache

func (*RedisCache) Contains

func (r *RedisCache) Contains(key string) bool

Contains checks if a key exists in the Redis cache

func (*RedisCache) Get

func (r *RedisCache) Get(key string) interface{}

Get returns a cached item from Redis if it exists

func (*RedisCache) Set

func (r *RedisCache) Set(key string, value interface{})

Set saves an item into Redis cache

Jump to

Keyboard shortcuts

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