golang / groupcache

groupcache is a caching and cache-filling library, intended as a replacement for memcached in many cases.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Concurrent access to lru.Cache

abennett opened this issue · comments

It doesn't look like lru.Cache is safe for concurrent access. Is this correct? If so, would you be opposed to me adding in a mutex?

I'm new to open source contribution and this looks like it might be an easy win.

What would be the downsides of replacing the current map with the new sync.Map?

Hi,

I hope I am not being redundant in responding but I notice that this thread has been silent for a bit.

From looking in groupcache.go, the lru is only used in a thread-safe manner. So the LRU leaves it's locking policy up to the calling code. I think that's reasonable, because then double-locks can be avoided - there's no question of who has to implement the locking, or where it should go in the code.

There are a couple of resources on sync.Map:
https://www.youtube.com/watch?v=C1EtfDnsdDs
https://medium.com/@deckarep/the-new-kid-in-town-gos-sync-map-de24a6bf7c2c

So, I guess the question is: do you have a measured cache contention problem in groupcache? :-)

Cheers,

Not redundant at all, and your comments make sense. I am satisfied. Thank you!