org.springframework.data.redis.cache.RedisCache Java Examples

The following examples show how to use org.springframework.data.redis.cache.RedisCache. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RedisAutoCacheManager.java    From mica with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
protected RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfig) {
	if (StringUtil.isBlank(name) || !name.contains(StringPool.HASH)) {
		return super.createRedisCache(name, cacheConfig);
	}
	String[] cacheArray = name.split(StringPool.HASH);
	if (cacheArray.length < 2) {
		return super.createRedisCache(name, cacheConfig);
	}
	String cacheName = cacheArray[0];
	if (cacheConfig != null) {
		// 转换时间,支持时间单位例如:300ms,第二个参数是默认单位
		Duration duration = DurationStyle.detectAndParse(cacheArray[1], ChronoUnit.SECONDS);
		cacheConfig = cacheConfig.entryTtl(duration);
	}
	return super.createRedisCache(cacheName, cacheConfig);
}
 
Example #2
Source File: MultitenantCacheManager.java    From spring-microservice-exam with MIT License 6 votes vote down vote up
/**
 * 扩展@Cacheable,支持配置失效时间
 *
 * @param name        name
 * @param cacheConfig cacheConfig
 * @return RedisCache
 */
@Override
protected RedisCache createRedisCache(String name, RedisCacheConfiguration cacheConfig) {
    if (StringUtils.isBlank(name) || !name.contains(SPLIT_FLAG)) {
        return super.createRedisCache(name, cacheConfig);
    }
    String[] cacheArray = name.split(SPLIT_FLAG);
    if (cacheArray.length < CACHE_LENGTH) {
        return super.createRedisCache(name, cacheConfig);
    }
    String cacheName = cacheArray[0];
    if (cacheConfig != null) {
        // 从系统属性里读取超时时间
        long cacheAge = Long.getLong(cacheArray[1], -1);
        cacheConfig = cacheConfig.entryTtl(Duration.ofSeconds(cacheAge));
    }
    return super.createRedisCache(cacheName, cacheConfig);
}
 
Example #3
Source File: RedisAutoCacheManager.java    From black-shop with Apache License 2.0 6 votes vote down vote up
@Override
protected RedisCache createRedisCache(String name,@Nullable RedisCacheConfiguration cacheConfig) {
	if(StrUtil.isBlank(name) || !name.contains("#")){
		return super.createRedisCache(name, cacheConfig);
	}

	String[] cacheArray = name.split("#");
	if (cacheArray.length < 2) {
		return super.createRedisCache(name, cacheConfig);
	}
	if (cacheConfig != null) {
		long cacheTime = Long.parseLong(cacheArray[1]);
		cacheConfig = cacheConfig.entryTtl(Duration.ofSeconds(cacheTime));
	}
	return super.createRedisCache(name, cacheConfig);
}
 
Example #4
Source File: MyRedisCacheManager.java    From spring-boot-vue-admin with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
protected Collection<RedisCache> loadCaches() {
  final List<RedisCache> caches = new LinkedList<>();
  for (final Map.Entry<String, RedisCacheConfiguration> entry :
      this.initialCacheConfiguration.entrySet()) {
    caches.add(super.createRedisCache(entry.getKey(), entry.getValue()));
  }
  return caches;
}
 
Example #5
Source File: RedisL2CacheManager.java    From gateway-helper with Apache License 2.0 5 votes vote down vote up
@Override
protected RedisCache getMissingCache(String name) {
    Long expiresSeconds = expires.get(name);
    if (expiresSeconds != null) {
        return createRedisCache(name, RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues().entryTtl(Duration.ofSeconds(expiresSeconds)));
    } else {
        return createRedisCache(name, RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues());
    }
}
 
Example #6
Source File: RedisGenericCacheManager.java    From faster-framework-project with Apache License 2.0 5 votes vote down vote up
protected RedisCache createRedisCache(String name, @Nullable RedisCacheConfiguration cacheConfig) {
    //使用cacheName从genericCacheMap获取泛型类型,如果失败,使用默认方式创建cache。如果成功,创建泛型cache
    Type type = this.genericCacheMap.get(name);
    //重置超时时间和cacheName
    String cacheName = resetExpirationAndName(name);
    if (type == null) {
        return super.createRedisCache(cacheName, cacheConfig);
    }
    return new RedisGenericCache(cacheName, cacheWriter, determineConfiguration(type));
}
 
Example #7
Source File: MyRedisCacheManager.java    From DimpleBlog with Apache License 2.0 5 votes vote down vote up
@Override
protected Collection<RedisCache> loadCaches() {
    List<RedisCache> caches = new LinkedList<>();
    for (Map.Entry<String, RedisCacheConfiguration> entry : initialCacheConfiguration.entrySet()) {
        caches.add(super.createRedisCache(entry.getKey(), entry.getValue()));
    }
    return caches;
}
 
Example #8
Source File: RedisL2CacheManager.java    From api-gateway-old with Apache License 2.0 5 votes vote down vote up
@Override
protected RedisCache getMissingCache(String name) {
    Long expiresSeconds = expires.get(name);
    if (expiresSeconds != null) {
        return createRedisCache(name, RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues().entryTtl(Duration.ofSeconds(expiresSeconds)));
    } else {
        return createRedisCache(name, RedisCacheConfiguration.defaultCacheConfig().disableCachingNullValues());
    }
}
 
Example #9
Source File: AppCacheManager.java    From todolist with MIT License 5 votes vote down vote up
@Override
	protected RedisCache createCache(String cacheName) {
//		if(cacheName.equals("token")) {
//			return new RedisCache(cacheName, "token:".getBytes(), this.ops, 24*60*60);
//		}

		return super.createCache(cacheName);
	}
 
Example #10
Source File: CacheConfig.java    From springboot-plus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Override
protected Cache decorateCache(Cache cache) {
	return new RedisAndLocalCache(this, (RedisCache) cache);
}
 
Example #11
Source File: CacheConfig.java    From springboot-plus with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public RedisAndLocalCache(TowLevelCacheManager cacheManager, RedisCache redisCache) {
	this.redisCache = redisCache;
	this.cacheManager = cacheManager;
}
 
Example #12
Source File: RedisUtil.java    From perfect-ssm with Apache License 2.0 4 votes vote down vote up
public void init() {
    template = SpringUtil.getBean("redisTemplate");//RedisCacheConfig中定义了
    cache = new RedisCache(CACHE_NAME, CACHE_NAME.getBytes(), template, EXPIRE_TIME);
}