Commit bfe205bb authored by Deepak Prakash Karn's avatar Deepak Prakash Karn
Browse files

Merge branch 'devbranch' into dpk_randomGenerationFix

parents ebc526f7 26f08ebb
1 merge request!83Dpk random int generation fix
Showing with 0 additions and 61 deletions
......@@ -7,70 +7,9 @@ package cachemdl
import (
"time"
"github.com/bluele/gcache"
"github.com/patrickmn/go-cache"
)
// GCCacheHelper use this to create new cache object
// Remember it holds memory
type GCCacheHelper struct {
GC gcache.Cache
Expiration time.Duration
MaxEntries int
}
//Setup create new object of GC
func (gchelper *GCCacheHelper) Setup(MaxEntries int, Expiration time.Duration) {
gchelper.MaxEntries = MaxEntries
gchelper.Expiration = Expiration
gchelper.GC = gcache.New(MaxEntries).
LFU().
Build()
}
//TODO: Check if you have SetUp value
// //Setup create new object of GC
// func (gchelper *GCCacheHelper) SetupWithCallbackFunction(MaxEntries int, Expiration time.Duration, f func(key interface{}, value interface{}) error) {
// gchelper.MaxEntries = MaxEntries
// gchelper.Expiration = Expiration
// gchelper.GC = gcache.New(MaxEntries).
// LFU().
// EvictedFunc(func(key, value interface{}) {
// f(key, value)
// }).
// Build()
// }
//New Add new Key and value
func (gchelper *GCCacheHelper) Set(key string, object interface{}) error {
return gchelper.GC.SetWithExpire(key, object, gchelper.Expiration)
}
//Get object based on key
func (gchelper *GCCacheHelper) Get(key string) (interface{}, error) {
return gchelper.GC.Get(key)
}
// GetAll objects from gc
func (gchelper *GCCacheHelper) GetAll() map[interface{}]interface{} {
return gchelper.GC.GetALL()
}
// Remove object from GC
func (gchelper *GCCacheHelper) Remove(key string) bool {
return gchelper.GC.Remove(key)
}
//Purge all objects
func (gchelper *GCCacheHelper) Purge() {
gchelper.GC.Purge()
}
// Count all objects
func (gchelper *GCCacheHelper) Count() int {
return gchelper.GC.Len()
}
type FastCacheHelper struct {
FastCache *cache.Cache
Expiration time.Duration
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment