Documentation ¶
Index ¶
- Variables
- type Cache
- type CacheEngine
- type CacheWithSubcache
- func (cs *CacheWithSubcache) Delete(key string) error
- func (cs *CacheWithSubcache) Get(key string) (interface{}, error)
- func (cs *CacheWithSubcache) Keys() ([]string, error)
- func (cs *CacheWithSubcache) Peek(key string) (interface{}, error)
- func (cs *CacheWithSubcache) Purge() error
- func (cs *CacheWithSubcache) Set(key string, value interface{}) error
- type DummyLogger
- type LRUCache
- type Logger
- type RedisCache
- func (rc *RedisCache) Delete(key string) error
- func (rc *RedisCache) Get(key string) (interface{}, error)
- func (rc *RedisCache) Keys() ([]string, error)
- func (rc *RedisCache) Peek(key string) (interface{}, error)
- func (rc *RedisCache) Purge() error
- func (rc *RedisCache) Set(key string, value interface{}) error
Constants ¶
This section is empty.
Variables ¶
var (
ErrNotFound = errors.New("Key not found")
)
Errors
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct { CacheEngine // contains filtered or unexported fields }
Cache is an implementation of a cache (key-value store). It needs to be provided with cache engine.
func MakeCache ¶
func MakeCache(engine CacheEngine) *Cache
MakeCache creates cache with provided engine
func (*Cache) DeleteWithPrefix ¶
DeleteWithPrefix removes all keys that start with given prefix
type CacheEngine ¶
type CacheEngine interface { Get(key string) (interface{}, error) Peek(key string) (interface{}, error) Set(key string, value interface{}) error Delete(key string) error Keys() ([]string, error) Purge() error }
CacheEngine is an interface for cache engine (e.g. in-memory cache or Redis Cache)
type CacheWithSubcache ¶
CacheWithSubcache is a Cache with L1 subcache.
func (*CacheWithSubcache) Delete ¶
func (cs *CacheWithSubcache) Delete(key string) error
Delete removes a key from cache
func (*CacheWithSubcache) Get ¶
func (cs *CacheWithSubcache) Get(key string) (interface{}, error)
Get gets a cached value by key
func (*CacheWithSubcache) Keys ¶
func (cs *CacheWithSubcache) Keys() ([]string, error)
Keys returns a slice of all keys in the cache
func (*CacheWithSubcache) Peek ¶
func (cs *CacheWithSubcache) Peek(key string) (interface{}, error)
Peek gets a cached key value without side-effects (i.e. without adding to L1 cache)
func (*CacheWithSubcache) Purge ¶
func (cs *CacheWithSubcache) Purge() error
Purge removes all the records from the cache
func (*CacheWithSubcache) Set ¶
func (cs *CacheWithSubcache) Set(key string, value interface{}) error
Set stores a key-value pair into cache
type DummyLogger ¶
type DummyLogger struct{}
DummyLogger is implementation of Logger that does not log anything
type LRUCache ¶
type LRUCache struct {
// contains filtered or unexported fields
}
LRUCache is a wrapper of hashicorp's golang-lru cache which implements cachier.Cache interface
func NewLRUCache ¶
NewLRUCache is a constructor that creates LRU cache of given size
type Logger ¶
type Logger interface { Error(...interface{}) Warn(...interface{}) Print(...interface{}) }
Logger is interface for logging
type RedisCache ¶
type RedisCache struct {
// contains filtered or unexported fields
}
RedisCache implements cachier.CacheTTL interface using redis storage
func NewRedisCache ¶
func NewRedisCache( redisClient *redis.Client, keyPrefix string, marshal func(value interface{}) ([]byte, error), unmarshal func(b []byte, value *interface{}) error, ttl time.Duration, ) *RedisCache
NewRedisCache is a constructor that creates a RedisCache
func NewRedisCacheWithLogger ¶
func NewRedisCacheWithLogger( redisClient *redis.Client, keyPrefix string, marshal func(value interface{}) ([]byte, error), unmarshal func(b []byte, value *interface{}) error, ttl time.Duration, logger Logger, ) *RedisCache
NewRedisCacheWithLogger is a constructor that creates a RedisCache
func (*RedisCache) Delete ¶
func (rc *RedisCache) Delete(key string) error
Delete removes a key from cache
func (*RedisCache) Get ¶
func (rc *RedisCache) Get(key string) (interface{}, error)
Get gets a cached value by key
func (*RedisCache) Keys ¶
func (rc *RedisCache) Keys() ([]string, error)
Keys returns all the keys in the cache
func (*RedisCache) Peek ¶
func (rc *RedisCache) Peek(key string) (interface{}, error)
Peek gets a cached value by key without any sideeffects (identical as Get in this implementation)
func (*RedisCache) Purge ¶
func (rc *RedisCache) Purge() error
Purge removes all the records from the cache
func (*RedisCache) Set ¶
func (rc *RedisCache) Set(key string, value interface{}) error
Set stores a key-value pair into cache