mybatis-3 cache 源码赏析
2024-09-29 07:32:37
总结:
从缓存策略源码,可以分析java相关类库
mybatis-3/src/main/java/org/apache/ibatis/cache/decorators/SoftCache.java
package org.apache.ibatis.cache.decorators; | |
import java.lang.ref.ReferenceQueue; | |
import java.lang.ref.SoftReference; | |
import java.util.Deque; | |
import java.util.LinkedList; | |
import java.util.concurrent.locks.ReadWriteLock; | |
import org.apache.ibatis.cache.Cache; | |
https://github.com/mybatis/mybatis-3/blob/67a1c4ea5726c605d297398a8ab9a42ab7d4ebf1/src/main/java/org/apache/ibatis/cache/decorators/FifoCache.java
/**
* Copyright 2009-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.ibatis.cache.decorators; import java.util.Deque;
import java.util.LinkedList;
import java.util.concurrent.locks.ReadWriteLock; import org.apache.ibatis.cache.Cache; /**
* FIFO (first in, first out) cache decorator
*
* @author Clinton Begin
*/
public class FifoCache implements Cache { private final Cache delegate;
private final Deque<Object> keyList;
private int size; public FifoCache(Cache delegate) {
this.delegate = delegate;
this.keyList = new LinkedList<>();
this.size = 1024;
} @Override
public String getId() {
return delegate.getId();
} @Override
public int getSize() {
return delegate.getSize();
} public void setSize(int size) {
this.size = size;
} @Override
public void putObject(Object key, Object value) {
cycleKeyList(key);
delegate.putObject(key, value);
} @Override
public Object getObject(Object key) {
return delegate.getObject(key);
} @Override
public Object removeObject(Object key) {
return delegate.removeObject(key);
} @Override
public void clear() {
delegate.clear();
keyList.clear();
} @Override
public ReadWriteLock getReadWriteLock() {
return null;
} private void cycleKeyList(Object key) {
keyList.addLast(key);
if (keyList.size() > size) {
Object oldestKey = keyList.removeFirst();
delegate.removeObject(oldestKey);
}
} }
最新文章
- 转载自jguangyou的博客,XML基本属性大全
- 【温故而知新-Javascript】使用 Ajax
- 如何做一个avalon组件
- Android Notification通知栏使用
- [Asp.net MVC]Asp.net MVC5系列——Razor语法
- jvisualvm 使用
- redis 集群
- 【原版的:参赛作品】窥秘懒---android打开下拉手势刷新时代
- Maven 构建浏览器解析userAgent类
- Grid move
- [Javasript] 同时实现单击和双击事件
- ajax from 提交
- Power Network (poj 1459 网络流)
- 用UNetbootin轻松把Linux操作系统装进U盘
- BIND9源码分析之 多个view的情况下如何做dynamic update
- 第1课 学习C++的意义
- JavaScript的进阶之路(四)理解对象1
- 【BZOJ 3289】 3289: Mato的文件管理 (莫队)
- 一个月入门Python爬虫,轻松爬取大规模数据
- GNU Radio: 自定义 block 实例
热门文章
- WAMP运行分析
- JS有趣的单线程
- iOS 图片剪切和压缩的几个方法
- Linux oracle数据库创建表空间、用户并赋予权限
- {";errorCode";:50} 的解决办法
- 使用HTML5监测网站性能
- PostgreSQL主备切换
- codeforces水题100道 第九题 Codeforces Beta Round #63 (Div. 2) Young Physicist (math)
- C++中三种创建对象的方法【转】
- OpenStack cloud 第一天