mybatis中cache的类型

mybatis中cache的类型

 

 

PerpetualCache

永久缓存 一旦存入就一直保持,只要两个id相同就认为是两个相同的cache

SynchronizedCache

同步缓存

SerializedCache

序列化缓存

LoggingCache

日志缓存

WeakCache

弱引用缓存,可以看到代码和SoftCache如出一辙,就是SoftReference变成了WeakReference

使用到数据对象Deque  Deques can also be used as LIFO (Last-In-First-Out) stacks 是一个队列集合,支持队列两端插入和删除元素

SoftCache

软引用缓存,核心是SoftReference

涉及到的引用

Reference->WeakReference->SoftReference引用相关 对象回收相关

ScheduledCache

定时调度缓存,目的是每一小时清空一下缓存

private boolean clearWhenStale() {

//如果到时间了,清空一下缓存

if (System.currentTimeMillis() - lastClear > clearInterval) {

clear();

return true;

}

return false;

}

FifoCacheFIFO缓存

 这个类就是维护一个FIFO链表,其他都委托给所包装的cache去做。典型的装饰模式

Deque<Object> keyList//增加记录时判断如果记录已超过1024条,会移除链表的第一个元素,从而达到FIFO缓存效果

LruCache最近最少使用缓存

 

存了两个map,用LinkedHashMap实现最近最少策略

 

class LinkedHashMap<K,V>

extends HashMap<K,V>

implements Map<K,V>

 

void afterNodeAccess(Node<K,V> e) { // move node to last

LinkedHashMap.Entry<K,V> last;

if (accessOrder && (last = tail) != e) {

LinkedHashMap.Entry<K,V> p =

(LinkedHashMap.Entry<K,V>)e, b = p.before, a = p.after;

p.after = null;

if (b == null)

head = a;

else

b.after = a;

if (a != null)

a.before = b;

else

last = b;

if (last == null)

head = p;

else {

p.before = last;

last.after = p;

}

tail = p;

++modCount;

}

}

 

最近访问和最近插入都放到链表的后面,链表最前面的就是最长时间没有访问的节点

CacheKey缓存key

MyBatis 对于其 Key 的生成采取规则为:[mappedStementId + offset + limit + SQL + queryParams + environment]生成一个哈希码

 

https://my.oschina.net/lixin91/blog/620068

转载于:https://my.oschina.net/iioschina/blog/1921738

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值