Java time-based map/cache with expiring keys [closed]

Do any of you know of a Java Map or similar standard data store that automatically purges entries after a given timeout? This means aging, where the old expired entries “age-out” automatically.

Preferably in an open source library that is accessible via Maven?

I know of ways to implement the functionality myself and have done it several times in the past, so I’m not asking for advice in that respect, but for pointers to a good reference implementation.

WeakReference based solutions like WeakHashMap are not an option, because my keys are likely to be non-interned strings and I want a configurable timeout that’s not dependent on the garbage collector.

Ehcache is also an option I wouldn’t like to rely on because it needs external configuration files. I am looking for a code-only solution.

10 Answers
10

Leave a Comment