用番石榴缓存 [英] Caching with Guava

查看:120
本文介绍了用番石榴缓存的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪些Guava类适合线程安全缓存?我使用一个组合键,它是动态构造的,所以softKeys()没有意义,对吧?我看到ConcurentLinkedHashMap的某个地方,是不是要走的路?它已经在最近发布了吗?对不起请求的混乱方式...

What Guava classes are suitable for thread-safe caching? I use a composed key, which gets constructed on the fly, so softKeys() makes no sense, right? I saw somewhere ConcurentLinkedHashMap, is it the way to go? Is it already in the recent release? Sorry for the chaotic way of asking...

这个问题很老了,看着他答案可能是浪费时间。长期以来,有一个 CacheBuilder 这是要走的路。

This question is pretty old and looking through he answers could possible be a waste of time. Since long there's a CacheBuilder which is the way to go.

推荐答案

听起来像你想要 MapMaker.makeComputingMap ,但你提到 softKeys 所以我假设你是已经熟悉那个班级。

Sounds like you want MapMaker.makeComputingMap, but you mention softKeys so I assume you are already familiar with that class.

你对 softKeys 是正确的 - 如果你把钥匙写在上面它将无法工作 - 即时,因为 softKeys 导致地图使用 == 而不是等于用于密钥比较。但是你可以使用 softValues 到期,只要重新创建被驱逐的条目没有副作用。

You are right about softKeys - it will not work if you compose keys on-the-fly, because softKeys causes the map to use == instead of equals for key comparison. But you should be fine with softValues and expiration, as long as there is no side-effect from recreating an evicted entry.

这篇关于用番石榴缓存的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆