Java – object cache data structure with “object expiration”

Which data structure in Java is best suited for in memory object caching, where objects have a separate expiration time?

Basically, for caching, I can use map (where the key can be string), which provides put and get methods, and uses the sequential table of "timestamp" and "object" pairs to manage the expiration time Therefore, the cleanup thread can check the first list entry and delete the object after its expiration time (the first element should be deleted within o (1) time)

Solution

The build you describe is basically expiringmap There are other similar implementations, such as guava (see cache builder) – although I don't believe it supports expiration of every entry in expiringmap

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>