github.com/mundipagg/boleto-api@v0.0.0-20230620145841-3f9ec742599f/cache/cache.go (about) 1 package cache 2 3 import ( 4 "sync" 5 ) 6 7 var memcache map[string]interface{} 8 var mutex sync.Mutex 9 10 //Inicia o cache em memoria antes de executar a main 11 func init() { 12 memcache = make(map[string]interface{}) 13 } 14 15 //Get item do cache 16 func Get(key string) (interface{}, bool) { 17 k, ok := memcache[key] 18 return k, ok 19 } 20 21 //Set item no cache 22 func Set(key string, obj interface{}) { 23 mutex.Lock() 24 defer mutex.Unlock() 25 memcache[key] = obj 26 }