bluele / gcache

An in-memory cache library for golang. It supports multiple eviction policies: LRU, LFU, ARC
MIT License
2.6k stars 271 forks source link

Can getValue use RLock? #80

Open Cyufei87 opened 3 years ago

Cyufei87 commented 3 years ago

https://github.com/bluele/gcache/blob/ecee3be431d11477f158fa979219e6e90c20213e/simple.go#L123 can here use RLock to decrease lock race?

jrynd commented 1 year ago

sort of...getValue() checks if the item has expired, and deletes it if it has. So you'd have to convert the reader lock to a full lock.

jrynd commented 1 year ago

Also the cache engine supports a loaderFunc that will attempt to generate a value if it's not found in the cache. That would also require a real Lock.