mybatis中cache的类型

mybatis中cache的类型

 

 

PerpetualCache

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

SynchronizedCache

同步缓存缓存

SerializedCache

序列化缓存mybatis

LoggingCache

日志缓存app

WeakCache

弱引用缓存,能够看到代码和SoftCache一模一样,就是SoftReference变成了WeakReferencespa

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

SoftCache

软引用缓存,核心是SoftReference日志

涉及到的引用

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

ScheduledCache

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

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

相关文章
相关标签/搜索