ConcurrentLinkedHashMap继承了ConcurrentMap中非原子操作的默认方法(compute, computeIfAbsent, computeIfPresent,和merge)。Caffeine实现了这些Java8新增功能的原子操作。
ConcurrentMap
compute
computeIfAbsent
computeIfPresent
merge
ConcurrentLinkedHashMap要求权重的最小值为1。与Guava类似,Caffeine 要求权重的最小值为0,以表明在基于容量的驱逐策略中这个元素永远不会被驱逐。
ConcurrentLinkedHashMap从队列中处理驱逐通知,任何一个调用线程都可以从这个队列中获取驱逐通知。Caffeine则交给配置的executor去执行(默认: ForkJoinPool.commonPool())。
ConcurrentLinkedHashMap支持查看保留顺序的快照视图。Caffeine 则提供通过Cache.policy()获取的Policy.Eviction提供此功能,ascendingMapWithLimit表示coldest, 而 descendingMapWithLimit表示hottest。
Cache.policy()
Policy.Eviction
ascendingMapWithLimit
coldest
descendingMapWithLimit
hottest
ConcurrentLinkedHashMap序列化会保留元素并在序列化中拒绝对元素的驱逐。Caffeine和Guava一样,序列化后只保留配置并不会保留数据。
There was an error while loading. Please reload this page.