Mensa-API/cache/cache.go

30 lines
514 B
Go
Raw Normal View History

2024-03-27 16:41:57 +00:00
package cache
import (
2024-09-15 16:57:03 +00:00
"github.com/LeRoid-hub/Mensa-API/models"
2024-03-27 16:41:57 +00:00
)
2024-09-15 16:57:03 +00:00
var Cache = make(map[string]models.CacheItem)
func HasCacheData(key string) bool {
_, ok := Cache[key]
return ok
2024-03-27 16:41:57 +00:00
}
2024-09-15 16:57:03 +00:00
func GetCacheData(key string) string {
Item, ok := Cache[key]
if !ok {
return ""
}
return Item.GetData()
2024-03-27 16:41:57 +00:00
}
2024-09-15 16:57:03 +00:00
func SetCacheData(key string, data string, lifetime ...int64) {
Item, ok := Cache[key]
if !ok {
Item = models.CacheItem{}
}
Item.SetData(data, lifetime...)
Cache[key] = Item
2024-03-27 16:41:57 +00:00
}