I need a Map
(or any collection) that supports time-to-idle for entries and removes them automatically.
I know there is guava MapMaker
, but it expires its elements on subsequent read/write operations rather than automatically, by a running thread. Furthermore the expiration capabilities of MapMaker
are now moved to CacheBuilder
. The thing is, I don't want a cache - I want expiring elements
Is there something ready-to-use? (it's not hard to implement it myself, but it's better to reuse something)
Maybe: http://code.google.com/p/concurrentlinkedhashmap/wiki/ExpirableCache
Rather not... it has lots of unresolved imports.
If nothing else, you can supply a dummy CacheLoader
that just throws exceptions, then just don't call Cache.get
-- only interact with the asMap
view. It's not pretty, but we're working to support this case better in 11.0. Make sure you have Guava 10.0.1 if you try this.
And yes, Cache.cleanUp
is there for you to call as often as you want from whichever threads you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With