Search code examples
javacachinglinkedhashmaplru

Refreshing a LRU cache


I am implementing a cache using a map extended from LinkedHashMap (so I can implement removeEldestEntry). The old implementation used a regular hash map, refreshed at a set interval. I was wondering how I can keep the data in the cache current. I doubt I can just refresh at a specific time without messing up the point of LRU. Would it be particularly costly to query the DB for a time stamp on the entry?


Solution

  • I ended up going with the LinkedHashMap, ordered by access time and checking against the db for timestamps. This worked like a charm and greatly reduced the memory load of the application.