Java Code Examples for org.springframework.data.redis.cache.RedisCacheManager#setUsePrefix()

The following examples show how to use org.springframework.data.redis.cache.RedisCacheManager#setUsePrefix() . 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: RedisConfiguration.java    From heimdall with Apache License 2.0 5 votes vote down vote up
/**
 * Configures and returns a {@link CacheManager}.
 * 
 * @return {@link CacheManager}
 */
@Bean
public CacheManager cacheManager() {
     RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplateObject());
     redisCacheManager.setUsePrefix(true);
     
     return redisCacheManager;
}
 
Example 2
Source File: RedisConfiguration.java    From heimdall with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a configured {@link CacheManager}.
 * 
 * @return {@link CacheManager}
 */
@Bean
public CacheManager cacheManager() {
     RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplateObject());
     redisCacheManager.setUsePrefix(true);
     
     return redisCacheManager;
}
 
Example 3
Source File: RedisCacheConfig.java    From konker-platform with Apache License 2.0 5 votes vote down vote up
@Bean
public RedisCacheManager cacheManager(RedisTemplate templateRedis) {
    RedisCacheManager redisCacheManager = new RedisCacheManager(templateRedis);
    redisCacheManager.setTransactionAware(true);
    redisCacheManager.setLoadRemoteCachesOnStartup(true);
    redisCacheManager.setUsePrefix(true);

    return redisCacheManager;
}
 
Example 4
Source File: CacheConfig.java    From vics with MIT License 5 votes vote down vote up
@Primary
@Bean(name = "stats")
public CacheManager stats(RedisTemplate redisTemplate) {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
    cacheManager.setUsePrefix(true);
    cacheManager.setDefaultExpiration(TWENTY_MINS_SECS);
    return cacheManager;
}
 
Example 5
Source File: CacheConfig.java    From vics with MIT License 5 votes vote down vote up
@Bean(name = "longCache")
public CacheManager longCache(RedisTemplate redisTemplate) {
    RedisCacheManager cacheManager = new RedisCacheManager(redisTemplate);
    cacheManager.setUsePrefix(true);
    cacheManager.setDefaultExpiration(TEN_HOURS_SECS);
    return cacheManager;
}
 
Example 6
Source File: RedisConfig.java    From spring-boot-redis-guava-caffeine-cache with Apache License 2.0 5 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager manager = new RedisCacheManager(redisTemplate);
    manager.setUsePrefix(true);
    RedisCachePrefix cachePrefix = new RedisPrefix("prefix");
    manager.setCachePrefix(cachePrefix);
    // 整体缓存过期时间
    manager.setDefaultExpiration(3600L);
    // 设置缓存过期时间。key和缓存过期时间,单位秒
    Map<String, Long> expiresMap = new HashMap<>();
    expiresMap.put("user", 1000L);
    manager.setExpires(expiresMap);
    return manager;
}
 
Example 7
Source File: RedisCacheManagerCustomizers.java    From onetwo with Apache License 2.0 5 votes vote down vote up
@Override
	public void customize(RedisCacheManager cacheManager) {
		Map<String, Long> cacheExpires = getCacheConfigsFromProviders();
		
		Set<String> cacheNames = Sets.newHashSet();
		if(properties.getCacheNames()!=null){
			cacheNames.addAll(properties.getCacheNames());
		}
		cacheNames.addAll(cacheExpires.keySet());
		// 配置文件覆盖
		cacheNames.addAll(properties.getExpires().keySet());
		
		cacheManager.setCacheNames(ImmutableSet.copyOf(cacheNames));
		cacheManager.setDefaultExpiration(properties.getDefaultExpirationInSeconds());
		cacheManager.setLoadRemoteCachesOnStartup(properties.isLoadRemoteCachesOnStartup());
		cacheManager.setUsePrefix(properties.isUsePrefix());
		cacheManager.setTransactionAware(properties.isTransactionAware());
		cacheManager.setCachePrefix(new ZifishRedisCachePrefix(properties.getCacheKeyPrefix()));
		
		Map<String, Long> expires = Maps.newHashMap();
//		expires.putAll(getCacheExpiresFromProviders());
		expires.putAll(cacheExpires);
		expires.putAll(properties.expiresInSeconds());
		cacheManager.setExpires(expires);
		
		if(properties.isUseJsonRedisTemplate()){
			JsonRedisTemplate template = new JsonRedisTemplate(jedisConnectionFactory);
			ReflectUtils.setFieldValue(cacheManager, "redisOperations", template);
		}
		//GenericJackson2JsonRedisSerializer
	}