go-redis / cache

Cache library with Redis backend for Golang
https://redis.uptrace.dev/guide/go-redis-cache.html
BSD 2-Clause "Simplified" License
757 stars 95 forks source link

Store unmarshalled object in local cache instead of bytes #20

Closed bdbai closed 5 years ago

bdbai commented 6 years ago

We have a Go program consisting of hundreds of goroutines and they all need to access the same Redis cache key. Then the bytes in local cache is unmarshalled over and over again.

How about storing the unmarshalled object in the local cache?

vmihailenco commented 6 years ago

That is what the lib did previously, but it leads to sharing the object between multiple goroutines which causes nasty bugs if object is modified. You probably need to create a specialized cache just for your use case.

bdbai commented 6 years ago

Since the object is never modified, it possible to add a option to accomplish this?

vmihailenco commented 6 years ago

It should be possible. Do you care to send a PR?

bdbai commented 6 years ago

I am working on tests. Once it's done I will send a PR :)

vmihailenco commented 5 years ago

I prefer not to fix this. If you need better performance - use sync.Map or write something that works for your use case.