[英]Refreshing a LRU cache
I am implementing a cache using a map extended from LinkedHashMap (so I can implement removeEldestEntry). 我正在使用从LinkedHashMap扩展的地图实现缓存(因此我可以实现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.
我怀疑我是否可以在特定时间刷新而不弄乱LRU的观点。 Would it be particularly costly to query the DB for a time stamp on the entry?
在数据库中查询条目的时间戳是否特别昂贵?
为什么不使用OS Cache-毫无用处。
I ended up going with the LinkedHashMap, ordered by access time and checking against the db for timestamps. 我最后使用LinkedHashMap,按访问时间排序,并对照db检查时间戳。 This worked like a charm and greatly reduced the memory load of the application.
这就像一个魅力,大大减少了应用程序的内存负载。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.