go-cache icon indicating copy to clipboard operation
go-cache copied to clipboard

The efficiency of `Get` will decrease if too many `Set ` are executed

Open ivan1218zhang opened this issue 2 years ago • 1 comments

It's caused by the RWLock for the thread-safe. How about using sync.Map? It can increase the efficiency of Get.

ivan1218zhang avatar Aug 02 '23 08:08 ivan1218zhang

I don't think sync.Map would be a good default choice. Caches are gerenally read more freaquently that written to.

I would suggest sending your cache updates to a channel and recieving from it on a different goroutine in a loop (select with timeout) and updating the cache.

ilius avatar Aug 02 '23 09:08 ilius