fix: gitee#I1NLJC (#193)

This commit is contained in:
devezhao 2020-07-14 13:49:38 +08:00 committed by GitHub
parent 7a4faadb7c
commit 31fb824471
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 40 additions and 15 deletions

View file

@ -25,7 +25,12 @@ package com.rebuild.server.configuration;
* @since 01/04/2019
*/
public interface ConfigManager<T> {
/**
* 已删除项标记
*/
String DELETED_ITEM = "$$RB_DELETED$$";
/**
* 清理缓存
*

View file

@ -62,18 +62,19 @@ public class ClassificationManager implements ConfigManager<ID> {
final String ckey = "ClassificationNAME-" + itemId;
String[] cached = (String[]) Application.getCommonCache().getx(ckey);
if (cached != null) {
return cached;
return cached[0].equals(DELETED_ITEM) ? null : cached;
}
Object[] o = Application.createQueryNoFilter(
"select name,fullName from ClassificationData where itemId = ?")
.setParameter(1, itemId)
.unique();
if (o != null) {
cached = new String[] { (String) o[0], (String) o[1] };
Application.getCommonCache().putx(ckey, cached);
}
return cached;
if (o != null) cached = new String[] { (String) o[0], (String) o[1] };
// 可能已删除
if (cached == null) cached = new String[] { DELETED_ITEM, DELETED_ITEM };
Application.getCommonCache().putx(ckey, cached);
return cached[0].equals(DELETED_ITEM) ? null : cached;
}
/**

View file

@ -39,7 +39,7 @@ public class PickListManager implements ConfigManager<Object> {
public static final PickListManager instance = new PickListManager();
protected PickListManager() { }
/**
* @param field
* @return
@ -119,18 +119,19 @@ public class PickListManager implements ConfigManager<Object> {
final String ckey = "PickListLABEL-" + itemId;
String cached = Application.getCommonCache().get(ckey);
if (cached != null) {
return cached;
return cached.equals(DELETED_ITEM) ? null : cached;
}
Object[] o = Application.createQueryNoFilter(
"select text from PickList where itemId = ?")
.setParameter(1, itemId)
.unique();
if (o != null) {
cached = (String) o[0];
}
if (o != null) cached = (String) o[0];
// 可能已删除
if (cached == null) cached = DELETED_ITEM;
Application.getCommonCache().put(ckey, cached);
return cached;
return cached.equals(DELETED_ITEM) ? null : cached;
}
/**

View file

@ -79,6 +79,10 @@ public abstract class BaseCacheTemplate<V extends Serializable> implements Cache
@Override
public void put(String key, String value, int seconds) {
if (value == null) {
LOG.warn("Can't set `" + key + "` to null");
return;
}
delegate.put(unityKey(key), value, seconds);
}
@ -94,6 +98,10 @@ public abstract class BaseCacheTemplate<V extends Serializable> implements Cache
@Override
public void putx(String key, V value, int seconds) {
if (value == null) {
LOG.warn("Can't set `" + key + "` to null");
return;
}
delegate.putx(unityKey(key), value, seconds);
}

View file

@ -25,6 +25,7 @@ import org.springframework.cache.Cache.ValueWrapper;
import org.springframework.cache.CacheManager;
import java.io.Serializable;
import java.util.Objects;
/**
* ehcache
@ -53,6 +54,8 @@ public class EhcacheDriver<V extends Serializable> implements CacheTemplate<V> {
@Override
public void put(String key, String value, int seconds) {
Objects.requireNonNull(value, "`value` not be null");
Element el = new Element(key, value);
if (seconds > -1) {
el.setTimeToLive(seconds);
@ -74,6 +77,8 @@ public class EhcacheDriver<V extends Serializable> implements CacheTemplate<V> {
@Override
public void putx(String key, V value, int seconds) {
Objects.requireNonNull(value, "`value` not be null");
Element el = new Element(key, value);
if (seconds > -1) {
el.setTimeToLive(seconds);

View file

@ -24,6 +24,7 @@ import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import java.io.Serializable;
import java.util.Objects;
/**
* redis
@ -58,6 +59,8 @@ public class JedisCacheDriver<V extends Serializable> implements CacheTemplate<V
@Override
public void put(String key, String value, int seconds) {
Objects.requireNonNull(value, "`value` not be null");
Jedis jedis = null;
try {
jedis = jedisPool.getResource();
@ -99,6 +102,8 @@ public class JedisCacheDriver<V extends Serializable> implements CacheTemplate<V
@Override
public void putx(String key, V value, int seconds) {
Objects.requireNonNull(value, "`value` not be null");
Jedis jedis = null;
try {
jedis = jedisPool.getResource();