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

The following examples show how to use org.springframework.data.redis.cache.RedisCacheManager#setDefaultExpiration() . 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: CacheService.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 5 votes vote down vote up
/**
 * 管理缓存
 *
 * @param redisTemplate
 * @return
 */

@SuppressWarnings("rawtypes")
@Bean
public CacheManager CacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
    // 设置cache过期时间,时间单位是秒
    rcm.setDefaultExpiration(60);
    Map<String, Long> map = new HashMap<String, Long>();
    map.put("test", 60L);
    rcm.setExpires(map);
    return rcm;
}
 
Example 2
Source File: CacheService.java    From SpringBoot-Dubbo-Docker-Jenkins with Apache License 2.0 5 votes vote down vote up
/**
 * 管理缓存
 *
 * @param redisTemplate
 * @return
 */

@SuppressWarnings("rawtypes")
@Bean
public CacheManager CacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
    // 设置cache过期时间,时间单位是秒
    rcm.setDefaultExpiration(60);
    Map<String, Long> map = new HashMap<String, Long>();
    map.put("test", 60L);
    rcm.setExpires(map);
    return rcm;
}
 
Example 3
Source File: RedisCacheConfiguration.java    From fw-cloud-framework with MIT License 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
	RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate);
	redisCacheManager.setDefaultExpiration(expiration);
	return redisCacheManager;
}
 
Example 4
Source File: CacheService.java    From springboot-learn with MIT License 5 votes vote down vote up
/**
 * 管理缓存
 *
 * @param redisTemplate
 * @return
 */

@SuppressWarnings("rawtypes")
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
    // 设置cache过期时间,时间单位是秒
    rcm.setDefaultExpiration(60);
    Map<String, Long> map = new HashMap<String, Long>();
    map.put("test", 60L);
    rcm.setExpires(map);
    return rcm;
}
 
Example 5
Source File: RedisCacheConfig.java    From SuperBoot with MIT License 5 votes vote down vote up
/**
 * 定义缓存对象
 *
 * @return
 */
@Bean
@Override
public CacheManager cacheManager() {
    String[] cacheNames = {"cache", "users", "roles", "modules", "mails",
            "apis", "configs", "info", "groups", "auths",
            "items", "menus", "menupermissions", "resource", "permissions", "permissionsResource",
            "rolemenu", "customers", "duties", "employees", "orgs", "userDetails", "sensitive"};
    RedisCacheManager redisCacheManager = new RedisCacheManager(redisTemplate(), Arrays.asList(cacheNames));
    //设置缓存过期时间 默认1天
    redisCacheManager.setDefaultExpiration(86400);
    return redisCacheManager;
}
 
Example 6
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 7
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 8
Source File: RedisCacheConfiguration.java    From spring-boot-with-multi-redis with MIT License 5 votes vote down vote up
@Primary
@Bean(name = "userCacheManager")
public CacheManager userCacheManager() {
    RedisCacheManager redisCacheManager = new RedisCacheManager(userRedisTemplate);
    redisCacheManager.setDefaultExpiration(3600);
    return redisCacheManager;
}
 
Example 9
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 10
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
	}
 
Example 11
Source File: RedisCacheConfig.java    From pig with MIT License 4 votes vote down vote up
@Bean
public CacheManager cacheManager(RedisTemplate redisTemplate) {
    RedisCacheManager rcm = new RedisCacheManager(redisTemplate);
    rcm.setDefaultExpiration(expiration);
    return rcm;
}
 
Example 12
Source File: RedisCacheConfiguration.java    From spring-boot-with-multi-redis with MIT License 4 votes vote down vote up
@Bean(name = "roleCacheManager")
public CacheManager roleCacheManager() {
    RedisCacheManager redisCacheManager = new RedisCacheManager(roleRedisTemplate);
    redisCacheManager.setDefaultExpiration(3600);
    return redisCacheManager;
}