Documentation ¶
Overview ¶
Package cachemdl will help cache object into memory. It Uses LRU algo
Index ¶
- Constants
- func FCWithCleanupInterval(ivl time.Duration) fastCacheOption
- func FCWithExpiration(exp time.Duration) fastCacheOption
- func FCWithMaxEntries(i int) fastCacheOption
- func RedisWithAddr(addr string) redisOption
- func RedisWithDB(db int) redisOption
- func RedisWithExpiration(exp time.Duration) redisOption
- func RedisWithPassword(p string) redisOption
- func RedisWithPrefix(pfx string) redisOption
- func RedisWithUsername(username string) redisOption
- type Cacher
- type FastCacheHelper
- func (fastCacheHelper *FastCacheHelper) Delete(key string)
- func (fastCacheHelper *FastCacheHelper) Get(key string) (interface{}, bool)
- func (fastCacheHelper *FastCacheHelper) GetAll() map[string]interface{}
- func (fastCacheHelper *FastCacheHelper) GetItems() map[string]cache.Item
- func (fastCacheHelper *FastCacheHelper) GetItemsCount() int
- func (fastCacheHelper *FastCacheHelper) Purge()
- func (fastCacheHelper *FastCacheHelper) Set(key string, object interface{})
- func (fastCacheHelper *FastCacheHelper) SetNoExpiration(key string, object interface{})
- func (fastCacheHelper *FastCacheHelper) SetWithExpiration(key string, object interface{}, duration time.Duration)
- func (fastCacheHelper *FastCacheHelper) Setup(maxEntries int, expiration time.Duration, cleanupTime time.Duration)
- func (fh *FastCacheHelper) Type() int
- type RedisCache
- func (rc *RedisCache) Delete(key string)
- func (rc *RedisCache) Get(key string) (interface{}, bool)
- func (rc *RedisCache) GetAll() map[string]interface{}
- func (rc *RedisCache) GetItemsCount() int
- func (rc *RedisCache) Purge()
- func (rc *RedisCache) Set(key string, val interface{})
- func (rc *RedisCache) SetNoExpiration(key string, val interface{})
- func (rc *RedisCache) SetWithExpiration(key string, val interface{}, exp time.Duration)
- func (rc *RedisCache) Setup(addr, username, password, prefix string, db int, exp time.Duration)
- func (rc *RedisCache) Type() int
Constants ¶
const ( // TypeFastCache indicates fast cache as cache storage TypeFastCache = iota + 1 // TypeRedisCache indicates redis server as cache storage. Use this in grid mode. TypeRedisCache )
Variables ¶
This section is empty.
Functions ¶
func FCWithCleanupInterval ¶
func FCWithExpiration ¶
func FCWithMaxEntries ¶
func FCWithMaxEntries(i int) fastCacheOption
func RedisWithAddr ¶
func RedisWithAddr(addr string) redisOption
func RedisWithDB ¶
func RedisWithDB(db int) redisOption
func RedisWithExpiration ¶
func RedisWithPassword ¶
func RedisWithPassword(p string) redisOption
func RedisWithPrefix ¶
func RedisWithPrefix(pfx string) redisOption
func RedisWithUsername ¶ added in v1.2.17
func RedisWithUsername(username string) redisOption
Types ¶
type Cacher ¶
type Cacher interface { // SET Set(key string, val interface{}) SetWithExpiration(key string, val interface{}, exp time.Duration) SetNoExpiration(key string, val interface{}) // GET Get(key string) (interface{}, bool) GetAll() map[string]interface{} // DELETE Delete(key string) Purge() // GetItemsCount GetItemsCount() int Type() int }
Cacher provides access to underlying cache, make sure all caches implement these methods.
The return types of data can be different. Ex. In case of redis cache it is `string`. The caller needs to handle this with the help of Type() method.
Ex. (Cacher{}).Type() == TypeRedisCache { // your implementation }
type FastCacheHelper ¶
type FastCacheHelper struct { FastCache *cache.Cache Expiration time.Duration CleanupTime time.Duration MaxEntries int }
FastCacheHelper -
func SetupFastCache ¶
func SetupFastCache(opts ...fastCacheOption) *FastCacheHelper
SetupFastCache initializes fastcache cache for application and returns its instance.
func (*FastCacheHelper) Delete ¶
func (fastCacheHelper *FastCacheHelper) Delete(key string)
Delete -
func (*FastCacheHelper) Get ¶
func (fastCacheHelper *FastCacheHelper) Get(key string) (interface{}, bool)
Get -
func (*FastCacheHelper) GetAll ¶
func (fastCacheHelper *FastCacheHelper) GetAll() map[string]interface{}
GetAll returns all keys with values present in memory. **This is not intended for production use. May hamper performance**
func (*FastCacheHelper) GetItems ¶
func (fastCacheHelper *FastCacheHelper) GetItems() map[string]cache.Item
GetItems -
func (*FastCacheHelper) GetItemsCount ¶
func (fastCacheHelper *FastCacheHelper) GetItemsCount() int
GetItemsCount : Number of items in the cache
func (*FastCacheHelper) Set ¶
func (fastCacheHelper *FastCacheHelper) Set(key string, object interface{})
Set -
func (*FastCacheHelper) SetNoExpiration ¶
func (fastCacheHelper *FastCacheHelper) SetNoExpiration(key string, object interface{})
SetNoExpiration -
func (*FastCacheHelper) SetWithExpiration ¶
func (fastCacheHelper *FastCacheHelper) SetWithExpiration(key string, object interface{}, duration time.Duration)
SetWithExpiration -
func (*FastCacheHelper) Setup ¶
func (fastCacheHelper *FastCacheHelper) Setup(maxEntries int, expiration time.Duration, cleanupTime time.Duration)
Setup initializes fastcache cache for application. Must be called only once.
func (*FastCacheHelper) Type ¶
func (fh *FastCacheHelper) Type() int
type RedisCache ¶
type RedisCache struct { Addr string // redis server address, default "127.0.0.1:6379" DB int // redis DB on provided server, default 0 Username string Password string // Expiration time.Duration // this duration will be used for Set() method Prefix string // this will be used for storing keys for provided project // contains filtered or unexported fields }
RedisCache represents a Redis client with provided configuration. Do not change configuration at runtime.
func SetupRedisCache ¶
func SetupRedisCache(opts ...redisOption) (*RedisCache, error)
SetupRedisCache initializes redis cache for application and returns it. Must be called only once.
func (*RedisCache) Get ¶
func (rc *RedisCache) Get(key string) (interface{}, bool)
Get returns data against provided key. Returns false if not present.
func (*RedisCache) GetAll ¶
func (rc *RedisCache) GetAll() map[string]interface{}
GetAll returns all keys with values present in redis server. Excludes the keys which does not have specified prefix. If prefix is empty, then returns all keys.
**This is not intended for production use. May hamper performance**
func (*RedisCache) Set ¶
func (rc *RedisCache) Set(key string, val interface{})
Set marshalls provided value and stores against provided key. Errors will be logged to initialized logger.
func (*RedisCache) SetNoExpiration ¶
func (rc *RedisCache) SetNoExpiration(key string, val interface{})
SetNoExpiration marshalls provided value and stores against provided key. Errors will be logged to initialized logger.
func (*RedisCache) SetWithExpiration ¶
func (rc *RedisCache) SetWithExpiration(key string, val interface{}, exp time.Duration)
SetWithExpiration marshalls provided value and stores against provided key for given duration. Errors will be logged to initialized logger.
func (*RedisCache) Setup ¶
func (rc *RedisCache) Setup(addr, username, password, prefix string, db int, exp time.Duration)
Setup initializes redis cache for application. Must be called only once.
func (*RedisCache) Type ¶
func (rc *RedisCache) Type() int