You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I got panic when try to get cache value with multiple runs.
panic: interface conversion: interface {} is []interface {}, not main.Users
Code to reproduce. Try this code 2 times.
package main
import (
"fmt""os""path/filepath""time""github.com/gookit/cache"
)
typeUserstruct {
Namestring
}
typeUsers []*Userconstkey="user1"funcmain() {
ifcache.Has(key) {
u, ok:=cache.Get("user1").(Users)
if!ok {
panic("can not assert cache data")
}
fmt.Printf("%#v\n", u[0])
}
u:=Users{&User{Name: "TestUser"}}
cache.Set(key, u, 1*time.Hour)
ifcache.Has(key) {
fmt.Println("cache written")
u2, ok:=cache.Get("user1").(Users)
if!ok||u[0] !=u2[0] {
fmt.Println("cache data is not OK")
} else {
fmt.Println("cache is ok")
}
}
}
funcinit() {
cache.Register(cache.DvrFile, cache.NewFileCache(filepath.Join(os.TempDir(), "tcache-dir")))
}
First time:
cache written
cache is ok
Second time:
panic: can not assert cache data
goroutine 1 [running]:
main.main()
/run/media/unikum/UNIKUM-STORAGE/private/prog/go/tcache/main.go:24 +0x28a
exit status 2
The text was updated successfully, but these errors were encountered:
Uh oh!
There was an error while loading. Please reload this page.
I got panic when try to get cache value with multiple runs.
Code to reproduce. Try this code 2 times.
First time:
Second time:
The text was updated successfully, but these errors were encountered: