|
@@ -51,8 +51,8 @@ public abstract class AbstractFeatureService<K, V> {
|
|
|
public AbstractFeatureService() {
|
|
|
this.emptyData = "{}";
|
|
|
// 单位秒
|
|
|
- this.emptyDataExpire = 60;
|
|
|
- this.defaultExpire = 7200;
|
|
|
+ this.emptyDataExpire = -1;
|
|
|
+ this.defaultExpire = -1;
|
|
|
this.keyFunc = k -> String.valueOf(k);
|
|
|
|
|
|
initLocalCache(defaultMaximumSize, defaultRefreshAfterWrite, defaultExpireAfterWrite, defaultExpireAfterAccess);
|
|
@@ -81,7 +81,7 @@ public abstract class AbstractFeatureService<K, V> {
|
|
|
protected V get(K key) {
|
|
|
assert cache != null;
|
|
|
try {
|
|
|
- return cache.get(key);
|
|
|
+ return cache.getUnchecked(key);
|
|
|
} catch (Exception e) {
|
|
|
log.error("get local cache error", e);
|
|
|
}
|
|
@@ -93,7 +93,6 @@ public abstract class AbstractFeatureService<K, V> {
|
|
|
V feature = getFromCache(key);
|
|
|
if (feature == null) {
|
|
|
feature = getFromSource(key);
|
|
|
- // TODO 可异步
|
|
|
saveToCache(key, feature);
|
|
|
}
|
|
|
return feature;
|
|
@@ -106,9 +105,10 @@ public abstract class AbstractFeatureService<K, V> {
|
|
|
}
|
|
|
|
|
|
private V getFromSource(K key) {
|
|
|
- String sourceKey = cacheKey(key);
|
|
|
- String value = tairTemplate.opsForValue().get(sourceKey);
|
|
|
- return JSONUtils.fromJson(value, typeToken, null);
|
|
|
+ return null;
|
|
|
+// String sourceKey = cacheKey(key);
|
|
|
+// String value = tairTemplate.opsForValue().get(sourceKey);
|
|
|
+// return JSONUtils.fromJson(value, typeToken, null);
|
|
|
}
|
|
|
|
|
|
private void saveToCache(K key, V value) {
|
|
@@ -119,6 +119,7 @@ public abstract class AbstractFeatureService<K, V> {
|
|
|
long expire = value == null
|
|
|
? emptyDataExpire
|
|
|
: defaultExpire;
|
|
|
+
|
|
|
// TODO 评估过期时间
|
|
|
redisTemplate.opsForValue().set(cacheKey, cacheValue, expire, TimeUnit.SECONDS);
|
|
|
}
|
|
@@ -167,15 +168,16 @@ public abstract class AbstractFeatureService<K, V> {
|
|
|
}
|
|
|
|
|
|
private Map<K, V> getFromSource(List<K> keys) {
|
|
|
- List<String> redisKeys = CommonCollectionUtils.toList(keys, this::cacheKey);
|
|
|
- List<String> values = tairTemplate.opsForValue().multiGet(redisKeys);
|
|
|
- Map<K, V> result = new HashMap<>();
|
|
|
- for (int i = 0; i < keys.size(); i++) {
|
|
|
- if (values.get(i) != null) {
|
|
|
- result.put(keys.get(i), JSONUtils.fromJson(values.get(i), typeToken, null));
|
|
|
- }
|
|
|
- }
|
|
|
- return result;
|
|
|
+ return Collections.emptyMap();
|
|
|
+// List<String> redisKeys = CommonCollectionUtils.toList(keys, this::cacheKey);
|
|
|
+// List<String> values = tairTemplate.opsForValue().multiGet(redisKeys);
|
|
|
+// Map<K, V> result = new HashMap<>();
|
|
|
+// for (int i = 0; i < keys.size(); i++) {
|
|
|
+// if (values.get(i) != null) {
|
|
|
+// result.put(keys.get(i), JSONUtils.fromJson(values.get(i), typeToken, null));
|
|
|
+// }
|
|
|
+// }
|
|
|
+// return result;
|
|
|
}
|
|
|
|
|
|
private void saveToCache(List<K> keys, Map<K, V> map) {
|