mirror of
https://github.com/LeRoid-hub/Mensa-API.git
synced 2025-01-31 03:34:57 +00:00
cache fix
This commit is contained in:
parent
c036ce104b
commit
69e3b61198
9
cache/cache.go
vendored
9
cache/cache.go
vendored
@ -9,7 +9,14 @@ import (
|
|||||||
var Cache = make(map[string]models.CacheItem)
|
var Cache = make(map[string]models.CacheItem)
|
||||||
|
|
||||||
func HasCacheData(key string) bool {
|
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
|
return ok
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -33,3 +33,10 @@ func (c *CacheItem) GetData() (Mensa, error) {
|
|||||||
|
|
||||||
return c.data, nil
|
return c.data, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *CacheItem) IsExpired() bool {
|
||||||
|
if time.Now().Unix()-c.lastUpdated.Unix() > c.lifetime {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user