bitbucket.org/alima123/expires@v0.0.0-20191226173914-cddaf5cffb3d/utils.go (about) 1 package expires 2 3 func (cm *CacheOpMap) CacheOperation(op string, key interface{}, opFunc func() DataExpires) (data DataExpires) { 4 var ( 5 cache = cm.LazyInitCachePoolOp(op) 6 ok bool 7 ) 8 data, ok = cache.Load(key) 9 if !ok { 10 data = opFunc() 11 if data != nil { 12 cache.Store(key, data) 13 } 14 return 15 } 16 17 return 18 } 19 20 func (cm *CacheOpMap) CacheOperationWithError(op string, key interface{}, opFunc func() (DataExpires, error)) (data DataExpires, err error) { 21 var ( 22 cache = cm.LazyInitCachePoolOp(op) 23 ok bool 24 ) 25 data, ok = cache.Load(key) 26 if !ok { 27 data, err = opFunc() 28 if err != nil { 29 return 30 } 31 cache.Store(key, data) 32 } 33 return 34 }