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