This commit is contained in:
parent
7a3fd4e400
commit
3c02969ffd
@ -51,16 +51,16 @@ 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)
|
||||
}
|
||||
*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()
|
||||
@ -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")
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user