go-redis/cache

Should Set respect SkipLocalCache?

Closed this issue · 4 comments

I stumbled across this through a bug in my application where the local cache had a longer TTL the the remote cache, which lead to unexpected behaviour.. However, using GetSkippingLocalCache fixed it.

While skimming through the source code I noticed that Itemhas the SkipLocalCache field, but the Set method does not use it. Wouldn't it be better to not use the local cache if the field is true, or is there some reason for this particular behaviour?

I think it would be quick to implement:

func (cd *Cache) set(item *Item) ([]byte, bool, error) { 
// ...
	if cd.opt.LocalCache != nil && !item.SkipLocalCache {
		cd.opt.LocalCache.Set(item.Key, b)
	}
// ....
}

Best regards,
Frido

Sounds good - this looks like an overlook on my side. Could you send a PR?

Sure, here you go #50 :-)

Thanks, should be in v8.2.2

Cool, thanks for the quick response!