Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Map with automatically expiring elements [closed]

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)

like image 685
Bozho Avatar asked Oct 13 '11 22:10

Bozho


2 Answers

Maybe: http://code.google.com/p/concurrentlinkedhashmap/wiki/ExpirableCache
Rather not... it has lots of unresolved imports.

like image 134
palacsint Avatar answered Oct 14 '22 12:10

palacsint


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.

like image 2
Kevin Bourrillion Avatar answered Oct 14 '22 13:10

Kevin Bourrillion