A call to Fetch after TagAsDeleted returns an old value
client := redis.NewClient(&redis.Options{
Addr: "localhost:6379",
Password: "",
DB: 0, // use default DB
})
rc := rockscache.NewClient(client, rockscache.NewDefaultOptions())
rc.Fetch("test1", 60 * time.Second, func () (string, error) {
return "test1", nil
})
rc.TagAsDeleted("test1")
value, _ := rc.Fetch("test1", 60 * time.Second, func () (string, error) {
return "test2", nil
})
fmt.Println("value:", value) // except return "test2", but got "test1"
you need set StrongConsistency to true,like this: rc.Options.StrongConsistency = true
client := redis.NewClient(&redis.Options{ Addr: "localhost:6379", Password: "", DB: 0, // use default DB }) rc := rockscache.NewClient(client, rockscache.NewDefaultOptions()) // enable strongConsistency rc.Options.StrongConsistency = true rc.Fetch("test1", 60 * time.Second, func () (string, error) { return "test1", nil }) rc.TagAsDeleted("test1") value, _ := rc.Fetch("test1", 60 * time.Second, func () (string, error) { return "test2", nil }) fmt.Println("value:", value)
I think strongConsistency should default to true, otherwise my above result would look like something was wrong @Wanghongw
For most cache system, they are eventual consistency, not strong consistency.
In most cases, performance is the most important
Performance of strong consistency is lower than eventual consistency