Closed thrawn01 closed 5 months ago
This is ready for review. @udhos, @gedw99 @Tochemey @Jvb182 @Baliedge @MatthewEdge
I'm also pinging @maypok86 to thank him for the wonderful otter cache! (I hope I'm using it correctly 😄 )
Please review and let me know what I missed or broke.
@thrawn01 Also for the cache rejected stats, is it a standard practice out there to reject item? If not I think then we are leaking otter custom feature here.
@thrawn01 Also for the cache rejected stats, is it a standard practice out there to reject item? If not I think then we are leaking otter custom feature here.
You can, it's your decision. I will even be a little glad, since I was not ready for the popularity of the otter. But I would like to tell you a little about the rejection. There are several ways in which this can happen in different caches.
@thrawn01 Also for the cache rejected stats, is it a standard practice out there to reject item? If not I think then we are leaking otter custom feature here.
Yes it's pretty common.
I wrote a section in the README called Cache Size Implications
to make users aware of the possibility of rejections. TLDR; Since we are using Otter for both main
and hot
caches and the hot
cache is 1/8th the size of the main
cache, and otter's max cost is calculated as 1/10th the max size of the cache it's possible that large items will be rejected from the hot
cache.
I considered making Otter the default cache implementation. But your reaction confirms my concern that users might be caught off guard, not understand why the hot cache might have a higher miss ratio than they expect.
@thrawn01 I believe like the discovery the contrib cache should go into another repository because of the different cache integration developers may want to add.
It's such a small include, it doesn't need it's own repo. Also, thanks to go mods Module graph pruning. Otter should not become a dependency of your project if contrib
isn't used by your project. It also becomes a great example of how to add your own third-party cache!
Purpose
To support alternative hot and main cache implementations that may have better performance under high concurrency workloads.
Implementation
Cache
interfaceModifications from original library
section to the bottom of the readme.cache
tomutexCache
and renamed some of it's internal variablesmutexCache
to implement the newCache
interfacemutexCache
frompopulateCache()
intomutexCache.Add()
Options.CacheFactory
to allow the initialization of third party cache implementationsgithub.com/maypok86/otter
CacheStats.Rejected
to count the number of items rejected by the cache.otter
in groupcache.SpawnServer() and
SpawnDaemon()to
ListenAndServe()`Usage
See #1