Browse Source

fix cache bug

Looly 5 years ago
parent
commit
8d81a59666

+ 1 - 0
CHANGELOG.md

@@ -10,6 +10,7 @@
 * 【core   】     multipart中int改为long,解决大文件上传越界问题(issue#I27WZ3@Gitee)
 
 ### Bug修复
+* 【cache  】     修复Cache中get重复misCount计数问题(issue#1281@Github)
 
 -------------------------------------------------------------------------------------------------------------
 

+ 5 - 7
hutool-cache/src/main/java/cn/hutool/cache/impl/AbstractCache.java

@@ -15,7 +15,7 @@ import java.util.concurrent.locks.StampedLock;
  * 继承此抽象缓存需要:<br>
  * <ul>
  * <li>创建一个新的Map</li>
- * <li>实现 <code>prune</code> 策略</li>
+ * <li>实现 {@code prune} 策略</li>
  * </ul>
  *
  * @param <K> 键类型
@@ -30,11 +30,11 @@ public abstract class AbstractCache<K, V> implements Cache<K, V> {
 	private final StampedLock lock = new StampedLock();
 
 	/**
-	 * 返回缓存容量,<code>0</code>表示无大小限制
+	 * 返回缓存容量,{@code 0}表示无大小限制
 	 */
 	protected int capacity;
 	/**
-	 * 缓存失效时长, <code>0</code> 表示无限制,单位毫秒
+	 * 缓存失效时长, {@code 0} 表示无限制,单位毫秒
 	 */
 	protected long timeout;
 
@@ -168,10 +168,8 @@ public abstract class AbstractCache<K, V> implements Cache<K, V> {
 				return null;
 			}
 
-			if (co.isExpired()) {
-				missCount.getAndIncrement();
-			} else {
-				// 命中
+			// 命中
+			if (false == co.isExpired()) {
 				hitCount.getAndIncrement();
 				return co.get(isUpdateLastAccess);
 			}

+ 1 - 0
hutool-db/src/main/java/cn/hutool/db/handler/RsHandler.java

@@ -19,6 +19,7 @@ import java.sql.SQLException;
  * @author Luxiaolei
  *
  */
+@FunctionalInterface
 public interface RsHandler<T> extends Serializable{
 	
 	/**