reliably forcing Guava map eviction to take place

后端 未结 7 1551
夕颜
夕颜 2021-01-03 21:04

EDIT: I\'ve reorganized this question to reflect the new information that since became available.

This question is based on the responses to a quest

7条回答
  •  太阳男子
    2021-01-03 21:45

    I was wondering the about the same issue you described in the first part of your question. From what I can tell from looking at the source code for Guava's CustomConcurrentHashMap (release 9), it appears that entries are evicted on the get(), put(), and replace() methods. The containsKey() method does not appear to invoke eviction. I'm not 100% sure because I took a quick pass at the code.

    Update:

    I also found a more recent version of the CustomConcurrentHashmap in Guava's git repository and it looks like containsKey() has been updated to invoke eviction.

    Both release 9 and the latest version I just found do not invoke eviction when size() is called.

    Update 2:

    I recently noticed that Guava r10 (yet to be released) has a new class called CacheBuilder. Basically this class is a forked version of the MapMaker but with caching in mind. The documentation suggests that it will support some of the eviction requirements you are looking for.

    I reviewed the updated code in r10's version of the CustomConcurrentHashMap and found what looks like a scheduled map cleaner. Unfortunately, that code appears unfinished at this point but r10 looks more and more promising each day.

提交回复
热议问题