Documentation
¶
Overview ¶
Package caching provides an easy abstraction layer for adding caching to an application
Index ¶
- type Cache
- type MemcachedDB
- func (m *MemcachedDB) CacheIncrement(key string, expiration time.Duration) error
- func (m *MemcachedDB) DeleteCacheIndex(indexKey string) (int, error)
- func (m *MemcachedDB) Get(key string) ([]byte, error)
- func (m *MemcachedDB) SetKey(key string, value string, ttl *time.Duration) error
- func (m *MemcachedDB) SetKeyIndex(indexKey string, member string) error
- type RedisDB
- func (r *RedisDB) CacheIncrement(key string, expiration time.Duration) error
- func (r *RedisDB) DeleteCacheIndex(indexKey string) (int, error)
- func (r *RedisDB) Get(key string) ([]byte, error)
- func (r *RedisDB) SetKey(key string, value string, ttl *time.Duration) error
- func (r *RedisDB) SetKeyIndex(indexKey, member string) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache interface {
//SetKey sets a key value pair. It prefixes the key provided
//with the specified prefix in the cacheConfig.
//in case the ttl is not specified it uses the default ttl specified in the config.
//if the ttl is not specified in the config. Then the expiration is at midnight
SetKey(key string, value string, ttl *time.Duration) error
SetKeyIndex(route string, key string) error
DeleteCacheIndex(indexKey string) (int, error)
Get(key string) ([]byte, error)
CacheIncrement(key string, expiration time.Duration) error
}
Cache All methods required to be implemented for a technology to be considered a cache
func GetCache ¶
GetCache is a factory that returns a caching layer for all methods that are commonly used for adding a caching layer to your API. gives flexibility when building and deploying the API. it allows for easy benchmarks and swapping technologies it is also easier for development to use redis for example in order to access the cache data with an app like RedisInsight
func SetUpRedisDB ¶
func SetUpRedisDB(c *cacheConfig) Cache
SetUpRedisDB initializes the redis instance and makes a ping to check the connection
type MemcachedDB ¶
type MemcachedDB struct {
// contains filtered or unexported fields
}
MemcachedDB provides a struct for the memcache implementation of caching
func SetUpMemcachedDB ¶
func SetUpMemcachedDB(opts *cacheConfig) *MemcachedDB
SetUpMemcachedDB initializes the memcache connection
func (*MemcachedDB) CacheIncrement ¶
func (m *MemcachedDB) CacheIncrement(key string, expiration time.Duration) error
func (*MemcachedDB) DeleteCacheIndex ¶
func (m *MemcachedDB) DeleteCacheIndex(indexKey string) (int, error)
DeleteCacheIndex clears the cache indexes for a provided route
func (*MemcachedDB) Get ¶
func (m *MemcachedDB) Get(key string) ([]byte, error)
Get returns bytes from memcache
func (*MemcachedDB) SetKey ¶
SetKey easier way to set a cache key Default expiration date is today at midnight
func (*MemcachedDB) SetKeyIndex ¶
func (m *MemcachedDB) SetKeyIndex(indexKey string, member string) error
SetKeyIndex appends to the list of keys A list of the cached keys is maintained in the cache with no expiration so when it comes to invalidating routes with dynamic filters you know all the cached keys
type RedisDB ¶
type RedisDB struct {
// contains filtered or unexported fields
}
RedisDB is the redis client implementation of cache
func (*RedisDB) CacheIncrement ¶
func (*RedisDB) DeleteCacheIndex ¶
DeleteCacheIndex clears the cache indexes for a provided route
func (*RedisDB) SetKeyIndex ¶
SetKeyIndex sets indexes for a key. Uses the underline set in redis