rockscache icon indicating copy to clipboard operation
rockscache copied to clipboard

A call to Fetch after TagAsDeleted returns an old value

Open hoslo opened this issue 2 years ago • 4 comments

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"

hoslo avatar Feb 22 '23 10:02 hoslo

you need set StrongConsistency to true,like this: rc.Options.StrongConsistency = true

Wanghongw avatar Feb 24 '23 03:02 Wanghongw

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)

Wanghongw avatar Feb 24 '23 03:02 Wanghongw

I think strongConsistency should default to true, otherwise my above result would look like something was wrong @Wanghongw

hoslo avatar Feb 24 '23 03:02 hoslo

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

yedf2 avatar Feb 24 '23 11:02 yedf2