Documentation ¶
Index ¶
- Variables
- func InitReadOnlyRedisCache(readOnlyCacheURL string, cachePassword string, ...) (interface{}, error)
- func InitRedisCache(useSentinel bool, defaultExpSeconds int, redisPassword []byte, ...) (interface{}, error)
- func NewSentinelPool(sentinelAddrs []string, masterIdentifier []byte, redisPassword []byte, ...) *redis.Pool
- type GenericCache
- func (c *GenericCache) Add(key string, data interface{}, exp time.Duration) (err error)
- func (c *GenericCache) AddExistingEntry(key string, entry GenericCacheEntry, expiresAt int64) error
- func (c *GenericCache) Decrement(key string, n uint64) (newValue uint64, err error)
- func (c *GenericCache) Delete(key string) (err error)
- func (c *GenericCache) Exists(key string) (found bool, entry GenericCacheEntry, err error)
- func (c *GenericCache) Flush() error
- func (c *GenericCache) Get(key string, value interface{}) error
- func (c *GenericCache) GetKey(entryData []byte) string
- func (c *GenericCache) Increment(key string, n uint64) (newValue uint64, err error)
- func (c *GenericCache) NewGenericCacheEntry(data interface{}, exp time.Duration) GenericCacheEntry
- func (c *GenericCache) RedisExpireAt(key string, epoc uint64) error
- func (c *GenericCache) RedisGetExpiresIn(key string) (int64, error)
- func (c *GenericCache) RedisIncrementAtomic(key string, n uint64) (newValue uint64, err error)
- func (c *GenericCache) RedisIncrementCheckSet(key string, n uint64) (newValue uint64, err error)
- func (c *GenericCache) Replace(key string, data interface{}, exp time.Duration) (err error)
- func (c *GenericCache) Set(key string, data interface{}, exp time.Duration) (err error)
- type GenericCacheEntry
- type InMemoryStore
- func (c *InMemoryStore) Add(key string, value interface{}, exp time.Duration) error
- func (c *InMemoryStore) Decrement(key string, n uint64) (uint64, error)
- func (c *InMemoryStore) Delete(key string) error
- func (c InMemoryStore) DeleteExpired()
- func (c *InMemoryStore) Flush() error
- func (c *InMemoryStore) Get(key string, value interface{}) error
- func (c *InMemoryStore) Increment(key string, n uint64) (uint64, error)
- func (c *InMemoryStore) Keys() []interface{}
- func (c *InMemoryStore) Len() int
- func (c *InMemoryStore) NewGenericCacheEntry(data interface{}, exp time.Duration) (newEntry GenericCacheEntry, err error)
- func (c *InMemoryStore) Replace(key string, value interface{}, exp time.Duration) error
- func (c *InMemoryStore) Set(key string, value interface{}, exp time.Duration) error
- func (c *InMemoryStore) Update(key string, entry GenericCacheEntry) error
- type Level
- type RedisConnectionInfo
- type Type
Constants ¶
This section is empty.
Variables ¶
var ( // ErrPaddingSize - represents padding errors ErrPaddingSize = errors.New("padding size error") )
var (
// PKCS5 represents pkcs5 struct
PKCS5 = &pkcs5{}
)
var (
// PKCS7 - difference with pkcs5 only block must be 8
PKCS7 = &pkcs5{}
)
Functions ¶
func InitReadOnlyRedisCache ¶
func InitReadOnlyRedisCache( readOnlyCacheURL string, cachePassword string, connectionTimeoutMilliseconds int, readWriteTimeoutMilliseconds int, defaultExpMinutes int, maxConnections int, selectDatabase int, logger *logrus.Entry) (interface{}, error)
InitReadOnlyRedisCache - used by microservices to init their read-only redis cache. Returns an interface{} so other caches could be swapped in
func InitRedisCache ¶
func InitRedisCache( useSentinel bool, defaultExpSeconds int, redisPassword []byte, connectionTimeoutMilliseconds int, readWriteTimeoutMilliseconds int, selectDatabase int, logger *logrus.Entry) (interface{}, error)
InitRedisCache - used by microservices to init their redis cache. Returns an interface{} so other caches could be swapped in - this uses ENV vars to figure out what to connect to. REDIS_MASTER_IDENTIFIER, REDIS_PASSWORD, REDIS_SENTINEL_ADDRESS
Types ¶
type GenericCache ¶
type GenericCache struct { Cache interface{} ReadCache *GenericCache DefaultExp time.Duration KeyPrefix []byte Logger *logrus.Entry EncryptData bool // contains filtered or unexported fields }
GenericCache - represents the cache
- Cache: empty interface to a persistent cache pool (could be writable if cType == Writable)
- ReadCache: empty interface to a persistent read-only cache pool (cType == ReadOnly)
- sharedSecret: used by GetKey() for generating signatures to be used as an entries primary key
- DefaultExp: the default expiry for entries
- cType: Writable or ReadOnly
- cLevel: L1 (level 1) or L2 (level 2)
- KeyPrefix: a prefex added to each key that's generated by GetKey()
- Logger: the logger to use when writing logs
func NewCacheWithMultiPools ¶
func NewCacheWithMultiPools(writeCachePool interface{}, readCachePool interface{}, cLevel Level, sharedSecret string, expirySeconds int, keyPrefix []byte, encryptData bool) *GenericCache
NewCacheWithMultiPools - creates a new generic cache for microservices using two Pools. One pool for writes and a separate pool for reads
func NewCacheWithPool ¶
func NewCacheWithPool(cachePool interface{}, cType Type, cLevel Level, sharedSecret string, expirySeconds int, keyPrefix []byte, encryptData bool) *GenericCache
NewCacheWithPool - creates a new generic cache for microservices using a Pool for connecting (this cache should be read/write)
func (*GenericCache) Add ¶
func (c *GenericCache) Add(key string, data interface{}, exp time.Duration) (err error)
Add - adds an entry to the cache
func (*GenericCache) AddExistingEntry ¶
func (c *GenericCache) AddExistingEntry(key string, entry GenericCacheEntry, expiresAt int64) error
AddExistingEntry -
func (*GenericCache) Decrement ¶
func (c *GenericCache) Decrement(key string, n uint64) (newValue uint64, err error)
Decrement - Decrement an entry in the cache
func (*GenericCache) Delete ¶
func (c *GenericCache) Delete(key string) (err error)
Delete - deletes an entry in the cache
func (*GenericCache) Exists ¶
func (c *GenericCache) Exists(key string) (found bool, entry GenericCacheEntry, err error)
Exists - searches the cache for an entry
func (*GenericCache) Flush ¶
func (c *GenericCache) Flush() error
Flush - Flush all the keys in the cache
func (*GenericCache) Get ¶
func (c *GenericCache) Get(key string, value interface{}) error
Get - retrieves and entry from the cache
func (*GenericCache) GetKey ¶
func (c *GenericCache) GetKey(entryData []byte) string
GetKey - return a key for the entryData
func (*GenericCache) Increment ¶
func (c *GenericCache) Increment(key string, n uint64) (newValue uint64, err error)
Increment - Increment an entry in the cache
func (*GenericCache) NewGenericCacheEntry ¶
func (c *GenericCache) NewGenericCacheEntry(data interface{}, exp time.Duration) GenericCacheEntry
NewGenericCacheEntry creates an entry with the data and all the time attribs set
func (*GenericCache) RedisExpireAt ¶
func (c *GenericCache) RedisExpireAt(key string, epoc uint64) error
RedisExpireAt - get the TTL of an entry
func (*GenericCache) RedisGetExpiresIn ¶
func (c *GenericCache) RedisGetExpiresIn(key string) (int64, error)
func (*GenericCache) RedisIncrementAtomic ¶
func (c *GenericCache) RedisIncrementAtomic(key string, n uint64) (newValue uint64, err error)
RedisIncrementAtomic - Increment an entry in the cache
func (*GenericCache) RedisIncrementCheckSet ¶
func (c *GenericCache) RedisIncrementCheckSet(key string, n uint64) (newValue uint64, err error)
RedisIncrementCheckSet - Increment an entry in the cache
type GenericCacheEntry ¶
GenericCacheEntry - represents a cached entry...
- Data: the entries data represented as an empty interface
- TimeAdded: epoc at the time of addtion
- ExpiresAd: epoc at the time of expiry
func (*GenericCacheEntry) Expired ¶
func (e *GenericCacheEntry) Expired() bool
Expired - is the entry expired?
type InMemoryStore ¶
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore - an in memory LRU store with expiry
func NewInMemoryStore ¶
func NewInMemoryStore(maxEntries int, defaultExpiration, cleanupInterval time.Duration, createMetric bool, metricLabel string) (*InMemoryStore, error)
NewInMemoryStore - create a new in memory cache
func (*InMemoryStore) Add ¶
func (c *InMemoryStore) Add(key string, value interface{}, exp time.Duration) error
Add - add an entry
func (*InMemoryStore) Decrement ¶
func (c *InMemoryStore) Decrement(key string, n uint64) (uint64, error)
Decrement (see CacheStore interface)
func (*InMemoryStore) Delete ¶
func (c *InMemoryStore) Delete(key string) error
Delete - delete an entry
func (InMemoryStore) DeleteExpired ¶
func (c InMemoryStore) DeleteExpired()
DeleteExpired - Delete all expired items from the cache.
func (*InMemoryStore) Flush ¶
func (c *InMemoryStore) Flush() error
Flush (see CacheStore interface)
func (*InMemoryStore) Get ¶
func (c *InMemoryStore) Get(key string, value interface{}) error
Get - Get an entry
func (*InMemoryStore) Increment ¶
func (c *InMemoryStore) Increment(key string, n uint64) (uint64, error)
Increment (see CacheStore interface)
func (*InMemoryStore) Len ¶
func (c *InMemoryStore) Len() int
Len - get the current count of entries in the cache
func (*InMemoryStore) NewGenericCacheEntry ¶
func (c *InMemoryStore) NewGenericCacheEntry(data interface{}, exp time.Duration) (newEntry GenericCacheEntry, err error)
NewGenericCacheEntry - create a new in memory cache entry
func (*InMemoryStore) Replace ¶
func (c *InMemoryStore) Replace(key string, value interface{}, exp time.Duration) error
Replace - replace an entry
func (*InMemoryStore) Set ¶
func (c *InMemoryStore) Set(key string, value interface{}, exp time.Duration) error
Set - set an entry
func (*InMemoryStore) Update ¶
func (c *InMemoryStore) Update(key string, entry GenericCacheEntry) error
Update - update an entry
type RedisConnectionInfo ¶
type RedisConnectionInfo struct { MasterIdentifier string // Redis Master identifieer - should come out of ENV from DBaaS and can be 0 len string (defaults to mymaster) Password string // Redis password - should be defined via an ENV and should default to 0 len string for no AUTH to Redis SentinelURL string // Sentinel URL - should be defined via an ENV from DBaaS and can be 0 len string when you don't want to use sentinel RedisURL string // Redis URL to use if we're not using sentinel UseSentinel bool // should be set via a config var - turn on/off sentinel use DefaultExpSeconds int // default expiry for redis entries - should be set via config ConnectionTimeoutMilliseconds int // Redis connection timeout - should be set via config ReadWriteTimeoutMilliseconds int // Redis read/write timeout - should be set via config SelectDatabase int // which Redis database to use - should be set via config }
RedisConnectionInfo - define all the things needed to manage a connection to redis (optionally using sentinel)