fix: cache bug
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Paul 2024-07-14 14:57:11 +02:00
parent 7a3fd4e400
commit 3c02969ffd

View File

@ -51,17 +51,17 @@ func (ip *IP) GetIPInfo(c echo.Context) (cached bool, err error) {
item, err := mc.Get(ip.IP)
if err != nil {
log.Println("error from cache", ip.IP, err)
return false, err
}
cached = false
} else {
cachedip := IP{}
err = json.Unmarshal(item.Value, &cachedip)
if err != nil {
log.Println(err)
return false, err
}
*ip = cachedip
return true, nil
}
}
err = ip.CheckIPAddress()
if err != nil {
@ -82,12 +82,12 @@ func (ip *IP) GetIPInfo(c echo.Context) (cached bool, err error) {
log.Println(err)
}
if mcenabled {
if mcenabled && !cached {
go func() {
dt, err := json.Marshal(*ip)
err = mc.Set(&memcache.Item{Key: ip.IP, Value: dt, Expiration: cacheMaxTime})
if err != nil {
log.Println(err)
log.Println(err, "test")
}
}()
}