//@author Ajit Jagtap //@version Thu Jul 05 2018 06:12:07 GMT+0530 (IST) // Package cachemdl will help cache object into memory. It Uses LRU algo package cachemdl import ( "time" "github.com/patrickmn/go-cache" ) type FastCacheHelper struct { FastCache *cache.Cache Expiration time.Duration CleanupTime time.Duration MaxEntries int } //Setup create new object of GC func (fastCacheHelper *FastCacheHelper) Setup(maxEntries int, expiration time.Duration, cleanupTime time.Duration) { fastCacheHelper.MaxEntries = maxEntries fastCacheHelper.Expiration = expiration fastCacheHelper.FastCache = cache.New(fastCacheHelper.Expiration, fastCacheHelper.CleanupTime) } func (fastCacheHelper *FastCacheHelper) Get(key string) (interface{}, bool) { return fastCacheHelper.FastCache.Get(key) } func (fastCacheHelper *FastCacheHelper) GetItems() map[string]cache.Item { return fastCacheHelper.FastCache.Items() } func (fastCacheHelper *FastCacheHelper) SetNoExpiration(key string, object interface{}) { fastCacheHelper.FastCache.Set(key, object, cache.NoExpiration) } func (fastCacheHelper *FastCacheHelper) Set(key string, object interface{}) { fastCacheHelper.FastCache.Set(key, object, cache.DefaultExpiration) } func (fastCacheHelper *FastCacheHelper) SetWithExpiration(key string, object interface{}, duration time.Duration) { fastCacheHelper.FastCache.Set(key, object, duration) } func (fastCacheHelper *FastCacheHelper) Purge() { fastCacheHelper.FastCache.Flush() } func (fastCacheHelper *FastCacheHelper) Delete(key string) { fastCacheHelper.FastCache.Delete(key) }