import "github.com/Bose/go-cache"
- Variables
- func InitReadOnlyRedisCache(readOnlyCacheURL string, cachePassword string, defaultExpMinutes int, maxConnections int, selectDatabase int, logger *logrus.Entry) (interface{}, error)
- func InitRedisCache(useSentinel bool, defaultExpSeconds int, redisPassword []byte, timeoutMilliseconds int, selectDatabase int, logger *logrus.Entry) (interface{}, error)
- func NewSentinelPool(sentinelAddrs []string, masterIdentifier []byte, redisPassword []byte, timeoutMilliseconds int, selectDatabase int, logger *logrus.Entry) *redis.Pool
- type GenericCache
- func NewCacheWithMultiPools(writeCachePool interface{}, readCachePool interface{}, cLevel Level, sharedSecret string, expirySeconds int, keyPrefix []byte, encryptData bool) *GenericCache
- func NewCacheWithPool(cachePool interface{}, cType Type, cLevel Level, sharedSecret string, expirySeconds int, keyPrefix []byte, encryptData bool) *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) 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 NewInMemoryStore(maxEntries int, defaultExpiration, cleanupInterval time.Duration) (*InMemoryStore, error)
- 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) 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
- type Level
- type Type
generic.go generic_test_store.go inmemory.go pkcs.go redispool.go
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{}
)
func InitReadOnlyRedisCache(readOnlyCacheURL string, cachePassword string, 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(useSentinel bool, defaultExpSeconds int, redisPassword []byte, timeoutMilliseconds 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
func NewSentinelPool(sentinelAddrs []string, masterIdentifier []byte, redisPassword []byte, timeoutMilliseconds int, selectDatabase int, logger *logrus.Entry) *redis.Pool
NewSentinelPool - create a new pool for Redis Sentinel
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(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(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 (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 (c *GenericCache) Decrement(key string, n uint64) (newValue uint64, err error)
Decrement - Decrement an entry in the cache
func (c *GenericCache) Delete(key string) (err error)
Delete - deletes an entry in the cache
func (c *GenericCache) Exists(key string) (found bool, entry GenericCacheEntry, err error)
Exists - searches the cache for an entry
func (c *GenericCache) Flush() error
Flush - Flush all the keys in the cache
func (c *GenericCache) Get(key string, value interface{}) error
Get - retrieves and entry from the cache
func (c *GenericCache) GetKey(entryData []byte) string
GetKey - return a key for the entryData
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 (c *GenericCache) Replace(key string, data interface{}, exp time.Duration) (err error)
Replace - Replace an entry in the cache
func (c *GenericCache) Set(key string, data interface{}, exp time.Duration) (err error)
Set - Set a key in the cache (over writting any existing entry)
type GenericCacheEntry struct {
Data interface{}
TimeAdded int64
ExpiresAt int64
}
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 (e *GenericCacheEntry) Expired() bool
Expired - is the entry expired?
type InMemoryStore struct {
// contains filtered or unexported fields
}
InMemoryStore - an in memory LRU store with expiry
func NewInMemoryStore(maxEntries int, defaultExpiration, cleanupInterval time.Duration) (*InMemoryStore, error)
NewInMemoryStore - create a new in memory cache
func (c *InMemoryStore) Add(key string, value interface{}, exp time.Duration) error
Add - add an entry
func (c *InMemoryStore) Decrement(key string, n uint64) (uint64, error)
Decrement (see CacheStore interface)
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 (c *InMemoryStore) Flush() error
Flush (see CacheStore interface)
func (c *InMemoryStore) Get(key string, value interface{}) error
Get - Get an entry
func (c *InMemoryStore) Increment(key string, n uint64) (uint64, error)
Increment (see CacheStore interface)
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 (c *InMemoryStore) Replace(key string, value interface{}, exp time.Duration) error
Replace - replace an entry
func (c *InMemoryStore) Set(key string, value interface{}, exp time.Duration) error
Set - set an entry
type Level int
Level - define a level for the cache: L1, L2, etc
const (
// L1 ...
L1 Level = iota + 1
// L2 ...
L2
)
type Type int
Type - define the type of cache: read or write
const (
// ReadOnly ...
ReadOnly Type = iota
// Writable ...
Writable
)
Generated by godoc2md