cache fix

This commit is contained in:
Jan 2024-09-16 18:29:34 +02:00
parent c036ce104b
commit 69e3b61198
2 changed files with 15 additions and 1 deletions

9
cache/cache.go vendored
View File

@ -9,7 +9,14 @@ import (
var Cache = make(map[string]models.CacheItem)
func HasCacheData(key string) bool {
_, ok := Cache[key]
data, ok := Cache[key]
if !ok {
return false
}
if data.IsExpired() {
delete(Cache, key)
return false
}
return ok
}

View File

@ -33,3 +33,10 @@ func (c *CacheItem) GetData() (Mensa, error) {
return c.data, nil
}
func (c *CacheItem) IsExpired() bool {
if time.Now().Unix()-c.lastUpdated.Unix() > c.lifetime {
return true
}
return false
}