-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cache eviction for CHMCache, or another default cache #29
Comments
As you mention, the |
I'm not a Java programmer, but this looks promising, and standard to Java 7 at least: http://chriswu.me/blog/a-lru-cache-in-10-lines-of-java/ implements a LRU Cache based on a LinkedHashMap in a mode (selected by constructor) to be ordered by access time. Worth noting from the docs:
|
Why not use something like https://github.com/ben-manes/caffeine ? |
We do not want to pull in a bunch of dependencies that many users will never use. Caffeine, in particular, also requires Java 8, while we still support 7. If you would like to use Caffeine, it is very easy to implement your own cache using |
Maybe consider ConcurrentLinkedHashMap if you want a tiny dependency, or an older (JDK7) Guava if already used? |
We tried implementing an LRU cache and the performance was strictly worse when looking up random IPs than Given this, I am going to close this issue without prejudice . Future PRs with alternate caching implementations will be considered on their merits. |
Right now CHMCache has no eviction policy - when it fills up, it never changes. But our GeoIP lookups are not just clustered (so benefiting from a cache) but also time-varying (benefiting from the cache changing over time). E.g. from around UTC 0:00 to 6:00, we switch from mostly-European to mostly-North-American IPs.
I understand that CHMCache is supposed to be mostly an example of how to write a cache, but we're dealing with applications written in JRuby, and that makes writing our own cache a little more painful and a lot slower.
Would it be possible to offer a default cache with an eviction policy?
The text was updated successfully, but these errors were encountered: