diff --git a/cache/cache.go b/cache/cache.go index 1564a98..827288e 100644 --- a/cache/cache.go +++ b/cache/cache.go @@ -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 } diff --git a/models/cacheItem.go b/models/cacheItem.go index 12ac6b0..f616c8b 100644 --- a/models/cacheItem.go +++ b/models/cacheItem.go @@ -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 +}