Documentation
      ¶
    
    
  
    
  
    Index ¶
- Constants
 - 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 WithCleanupInterval(ivl time.Duration) cacheOption
 - func WithExpiration(exp time.Duration) cacheOption
 - func WithMaxEntries(i int) cacheOption
 - type Cache
 - type CacheHelper
 - func (cacheHelper *CacheHelper) Delete(key string)
 - func (cacheHelper *CacheHelper) Get(key string) (interface{}, bool)
 - func (cacheHelper *CacheHelper) GetAll() map[string]interface{}
 - func (cacheHelper *CacheHelper) GetItems() map[string]cache.Item
 - func (cacheHelper *CacheHelper) GetItemsCount() int
 - func (cacheHelper *CacheHelper) LoadFile(fname string) error
 - func (cacheHelper *CacheHelper) Purge()
 - func (cacheHelper *CacheHelper) SaveFile(fname string) error
 - func (cacheHelper *CacheHelper) Set(key string, object interface{})
 - func (cacheHelper *CacheHelper) SetNoExpiration(key string, object interface{})
 - func (cacheHelper *CacheHelper) SetWithExpiration(key string, object interface{}, duration time.Duration)
 - func (cacheHelper *CacheHelper) Setup(maxEntries int, expiration time.Duration, cleanupTime time.Duration)
 - func (cacheHelper *CacheHelper) 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, password, prefix string, db int, exp time.Duration)
 - func (rc *RedisCache) Type() int
 
Constants ¶
const ( // TypeCache indicates fast cache as cache storage TypeCache = iota + 1 TypeRedisCache )
Variables ¶
This section is empty.
Functions ¶
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 WithCleanupInterval ¶
WithCleanupInterval returns the expired items clean up time
func WithExpiration ¶
WithExpiration returns the expiration time
func WithMaxEntries ¶
func WithMaxEntries(i int) cacheOption
WithMaxEntries returns the MaxEntries that can be accepted
Types ¶
type Cache ¶
type Cache interface {
	// Setters
	Set(key string, val interface{})
	SetWithExpiration(key string, val interface{}, exp time.Duration)
	SetNoExpiration(key string, val interface{})
	SaveFile(fname string)
	// Getters
	Get(key string) (interface{}, bool)
	GetAll() map[string]interface{}
	LoadFile(fname string)
	// Deletion operations
	Delete(key string)
	Purge()
	// GetItemsCount
	GetItemsCount() int
	Type() int
}
    Cache provides access to underlying cache, make sure all caches implement these methods.
type CacheHelper ¶
type CacheHelper struct {
	Cache       *cache.Cache
	Expiration  time.Duration
	CleanupTime time.Duration
	MaxEntries  int
}
    CacheHelper is a struct
func SetupCache ¶
func SetupCache(opts ...cacheOption) *CacheHelper
SetupCache initializes fastcache cache for application and returns its instance.
func (*CacheHelper) GetAll ¶
func (cacheHelper *CacheHelper) GetAll() map[string]interface{}
GetAll returns all keys with values present in memory. **This is not intended for production use. May hamper performance**
func (*CacheHelper) GetItems ¶
func (cacheHelper *CacheHelper) GetItems() map[string]cache.Item
GetItems -
func (*CacheHelper) GetItemsCount ¶
func (cacheHelper *CacheHelper) GetItemsCount() int
GetItemsCount : Number of items in the cache
func (*CacheHelper) LoadFile ¶
func (cacheHelper *CacheHelper) LoadFile(fname string) error
LoadFile to load saved file
func (*CacheHelper) SaveFile ¶
func (cacheHelper *CacheHelper) SaveFile(fname string) error
SaveFile is the
func (*CacheHelper) SetNoExpiration ¶
func (cacheHelper *CacheHelper) SetNoExpiration(key string, object interface{})
SetNoExpiration -
func (*CacheHelper) SetWithExpiration ¶
func (cacheHelper *CacheHelper) SetWithExpiration(key string, object interface{}, duration time.Duration)
SetWithExpiration -
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
	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, 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