Adjust cache to private variable
This commit is contained in:
parent
41605f743a
commit
20b21c0221
3 changed files with 24 additions and 6 deletions
|
@ -5,7 +5,7 @@ import (
|
|||
"time"
|
||||
)
|
||||
|
||||
var IPCache *Cache
|
||||
var ipCache *Cache
|
||||
|
||||
type Cache struct {
|
||||
store sync.Map
|
||||
|
@ -27,3 +27,24 @@ func (c *Cache) Get(key uint) (uint, bool) {
|
|||
value, ok := output.(uint)
|
||||
return value, ok
|
||||
}
|
||||
|
||||
func createCache() {
|
||||
ipCache = NewCache()
|
||||
}
|
||||
|
||||
func GetCacheContent(key uint) (uint, bool) {
|
||||
if ipCache == nil {
|
||||
createCache()
|
||||
return 0, false
|
||||
}
|
||||
|
||||
return ipCache.Get(key)
|
||||
}
|
||||
|
||||
func SetCacheContent(key, value uint, ttl time.Duration) {
|
||||
if ipCache == nil {
|
||||
createCache()
|
||||
}
|
||||
|
||||
ipCache.Set(key, value, ttl)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue