Commit 65981e3f by WeiCong

优化缓存模块

parent 4a9d88d8
...@@ -30,7 +30,7 @@ public abstract class AbstractCache implements CacheController { ...@@ -30,7 +30,7 @@ public abstract class AbstractCache implements CacheController {
Object o = cacheKey.getKey(); Object o = cacheKey.getKey();
String fullSizeKey = generateKey(o); String fullSizeKey = generateKey(o);
Integer fullSize = (Integer) doCacheRead(fullSizeKey); Integer fullSize = (Integer) doCacheRead(fullSizeKey);
if(fullSize == null) if (fullSize == null)
fullSize = 0; fullSize = 0;
if (fullSize == 0) { if (fullSize == 0) {
try { try {
...@@ -41,7 +41,13 @@ public abstract class AbstractCache implements CacheController { ...@@ -41,7 +41,13 @@ public abstract class AbstractCache implements CacheController {
} }
} }
String valKey = generateValKey(o, maxSize, offset); String valKey = generateValKey(o, maxSize, offset);
List lst = (List) doCacheRead(valKey); Object lstobj = doCacheRead(valKey);
List lst = null;
if (lstobj != null && List.class.isAssignableFrom(lstobj.getClass())) {
lst = List.class.cast(lstobj);
} else {
lst = null;
}
if (lst == null) { if (lst == null) {
if (o instanceof Criteria) { if (o instanceof Criteria) {
Criteria criteria = (Criteria) o; Criteria criteria = (Criteria) o;
...@@ -75,7 +81,9 @@ public abstract class AbstractCache implements CacheController { ...@@ -75,7 +81,9 @@ public abstract class AbstractCache implements CacheController {
throw new NoUiException("[" + this.cacheName + "]执行sql出现异常", e); throw new NoUiException("[" + this.cacheName + "]执行sql出现异常", e);
} }
} }
doCacheWrite(valKey, lst, keepAlive); if (lst != null) {
doCacheWrite(valKey, lst, keepAlive);
}
} }
return new CacheList(lst, fullSize); return new CacheList(lst, fullSize);
} }
...@@ -86,7 +94,7 @@ public abstract class AbstractCache implements CacheController { ...@@ -86,7 +94,7 @@ public abstract class AbstractCache implements CacheController {
sb.append(SPLIT.intern()); sb.append(SPLIT.intern());
sb.append(maxSize); sb.append(maxSize);
} }
if (offset > 0) { if (offset >= 0) {
sb.append(SPLIT.intern()); sb.append(SPLIT.intern());
sb.append(offset); sb.append(offset);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment