caching - Multiple file system caches causing havoc for each other -
relatively new go , can't figure out if i'm doing stupid (quite likely) or if there's bug (unlikely given i'm doing stupid). have 2 filesystem cache's using beego's filesystem cache. 2 separate folders. when try writing each cache try retrieve values results mixed up. can tell creation of mycache gets overridden othercache in init() function:
package main import ( "github.com/astaxie/beego/cache" "log" ) var ( mycache cache.cache othercache cache.cache err error ) func init() { if mycache, err = cache.newcache("file", `{"cachepath":".cache/mycache","filesuffix":".cache","directorylevel":1,"embedexpiry":10}`); err != nil { log.println(err) } if othercache, err = cache.newcache("file", `{"cachepath":".cache/othercache","filesuffix":".cache","directorylevel":1,"embedexpiry":10}`); err != nil { log.println(err) } } func checkcache(c cache.cache, k string) string { b := c.get(k) return b.(string) } func writecache(c cache.cache, k string, v string) { if err := c.put(k, v, 10); err != nil { log.println(err) } } func main() { log.setflags(log.lshortfile) init() log.println(mycache) log.println(othercache) // write mycache mykey := "mykey" myvalue := "myvalue" writecache(mycache, mykey, myvalue) // write othercache othervalue := "othervalue" writecache(othercache, mykey, othervalue) // mycache value myv := checkcache(mycache, mykey) log.println("mycache:", myv, myv == myvalue) // othercache value otherv := checkcache(othercache, mykey) log.println("othercache:", otherv, otherv == othervalue) }
result:
tester.go:34: &{/home/desktop-admin/desktop/eclipse/go/src/testfolder/tester/.cache/othercache .cache 2 0} tester.go:35: &{/home/desktop-admin/desktop/eclipse/go/src/testfolder/tester/.cache/othercache .cache 2 0} tester.go:47: mycache: othervalue false tester.go:51: othercache: othervalue true
the first line of output should point "mycache", not "othercache". also, third line of output wrong...value should "myvalue", not "othervalue".
am doing wrong here? (my other option have 1 filesystem cache & change key easier manage 2 different folders & delete entire cache if need be....i'd rather know i'm doing wrong here, however)
have @ implementation of newcache function:
https://github.com/astaxie/beego/blob/master/cache/cache.go#l84
this package allows 1 cache per adapter. second call newcache same adapter reconfigure , return same object.
Comments
Post a Comment