dubbo如何做cache缓存

duubo如何使用cache的?
CacheFilterclass里面有,这个filter既可以在provider也可以在consumer
if (cacheFactory != null && ConfigUtils.isNotEmpty(invoker.getUrl().getMethodParameter(invocation.getMethodName(), Constants.CACHE_KEY))) {
可见只要对方法url加了cache标志,就会使用cache,通过cacheFactory得到几个cache,重点说下lru的cache

lru-cache继承自LinkedHashMap,由于这个map没有线程安全,所以所有操作都加了排他锁。
既然是cache,为了更快读取到数据,肯定用hashmap,但是hashmap无法做到lru,为了解决这个问题,就用到了LinkedHashMap,这个map跟hashmap不同的地方就在于,链表部分是双向的,因此对于每次put进来Entry,除了将其保存到哈希表中对应的位置上之外,还会将其插入到双向链表的尾部(有头尾指针)来保证插入的顺序,从而达到lru的作用。

猜你喜欢

转载自www.cnblogs.com/notlate/p/10124850.html
今日推荐