Refreshing a LRU cache
-
09-10-2019 - |
Pergunta
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?
Solução 2
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.
Outras dicas
Why not use OS Cache - no point in reinventing the wheel.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow