update 优化 缓存注解支持关闭本地缓存

dev
疯狂的狮子Li 8 months ago
parent 52295bdc20
commit 5f91db4cbe

@ -3,13 +3,14 @@ package org.dromara.common.core.constant;
/** /**
* *
* <p> * <p>
* key cacheNames#ttl#maxIdleTime#maxSize * key cacheNames#ttl#maxIdleTime#maxSize#local
* <p> * <p>
* ttl 0 0 * ttl 0 0
* maxIdleTime LRU 0 0 * maxIdleTime LRU 0 0
* maxSize LRU 0 0 * maxSize LRU 0 0
* local 1 0
* <p> * <p>
* : test#60stest#0#60stest#0#1m#1000test#1h#0#500 * : test#60stest#0#60stest#0#1m#1000test#1h#0#500test#1h#0#500#0
* *
* @author Lion Li * @author Lion Li
*/ */

@ -145,18 +145,25 @@ public class PlusSpringCacheManager implements CacheManager {
if (array.length > 3) { if (array.length > 3) {
config.setMaxSize(Integer.parseInt(array[3])); config.setMaxSize(Integer.parseInt(array[3]));
} }
int local = 1;
if (config.getMaxIdleTime() == 0 && config.getTTL() == 0 && config.getMaxSize() == 0) { if (array.length > 4) {
return createMap(name, config); local = Integer.parseInt(array[4]);
} }
return createMapCache(name, config); if (config.getMaxIdleTime() == 0 && config.getTTL() == 0 && config.getMaxSize() == 0) {
return createMap(name, config, local);
}
return createMapCache(name, config, local);
} }
private Cache createMap(String name, CacheConfig config) { private Cache createMap(String name, CacheConfig config, int local) {
RMap<Object, Object> map = RedisUtils.getClient().getMap(name); RMap<Object, Object> map = RedisUtils.getClient().getMap(name);
Cache cache = new CaffeineCacheDecorator(name, new RedissonCache(map, allowNullValues)); Cache cache = new RedissonCache(map, allowNullValues);
if (local == 1) {
cache = new CaffeineCacheDecorator(name, cache);
}
if (transactionAware) { if (transactionAware) {
cache = new TransactionAwareCacheDecorator(cache); cache = new TransactionAwareCacheDecorator(cache);
} }
@ -167,10 +174,13 @@ public class PlusSpringCacheManager implements CacheManager {
return cache; return cache;
} }
private Cache createMapCache(String name, CacheConfig config) { private Cache createMapCache(String name, CacheConfig config, int local) {
RMapCache<Object, Object> map = RedisUtils.getClient().getMapCache(name); RMapCache<Object, Object> map = RedisUtils.getClient().getMapCache(name);
Cache cache = new CaffeineCacheDecorator(name, new RedissonCache(map, config, allowNullValues)); Cache cache = new RedissonCache(map, config, allowNullValues);
if (local == 1) {
cache = new CaffeineCacheDecorator(name, cache);
}
if (transactionAware) { if (transactionAware) {
cache = new TransactionAwareCacheDecorator(cache); cache = new TransactionAwareCacheDecorator(cache);
} }

@ -40,7 +40,7 @@ public class RedisCacheController {
* <p> * <p>
* cacheNames {@link CacheNames} * cacheNames {@link CacheNames}
*/ */
@Cacheable(cacheNames = "demo:cache#60s#10m#20", key = "#key", condition = "#key != null") @Cacheable(cacheNames = "demo:cache#60s#10m#20#1", key = "#key", condition = "#key != null")
@GetMapping("/test1") @GetMapping("/test1")
public R<String> test1(String key, String value) { public R<String> test1(String key, String value) {
return R.ok("操作成功", value); return R.ok("操作成功", value);

Loading…
Cancel
Save