How to implement a most-recently-used cache

后端 未结 4 985
孤独总比滥情好
孤独总比滥情好 2020-12-09 04:40

What would be the best way to implement a most-recently-used cache of objects?

Here are the requirements and restrictions...

  • Objects are stored as key/
4条回答
  •  猫巷女王i
    2020-12-09 05:25

    Another approach may be to take a look at section 5.6 in Java Concurrency in Practice by Brian Goetz: "Building an efficient, scalable result cache". Take a look at the Memoizer, although you may have to customize it for your purposes.

    As an aside, what I cannot figure out is why Java does not have a ConcurrentLinkedHashMap out of the box. This data structure would be very helpful for building a cache.

提交回复
热议问题