Java Code Examples for org.springframework.data.redis.cache.RedisCacheManager#RedisCacheManagerBuilder
The following examples show how to use
org.springframework.data.redis.cache.RedisCacheManager#RedisCacheManagerBuilder .
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: RedisConfig.java From DouBiNovel with Apache License 2.0 | 5 votes |
@Override @Bean public CacheManager cacheManager() { // 设置序列化 RedisSerializer<String> stringSerializer = new StringRedisSerializer(); FastJsonRedisSerializer<Object> fastJsonRedisSerializer = new FastJsonRedisSerializer<>(Object.class); RedisCacheConfiguration config = RedisCacheConfiguration.defaultCacheConfig() .serializeKeysWith(RedisSerializationContext.SerializationPair.fromSerializer(stringSerializer)) // value序列化方式 .serializeValuesWith(RedisSerializationContext.SerializationPair.fromSerializer(fastJsonRedisSerializer)) // .disableCachingNullValues() // 缓存过期时间 .entryTtl(Duration.ofMinutes(5)); RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder .fromConnectionFactory(lettuceConnectionFactory) .cacheDefaults(config) .transactionAware(); @SuppressWarnings("serial") Set<String> cacheNames = new HashSet<String>() { { add("codeNameCache"); } }; builder.initialCacheNames(cacheNames); return builder.build(); }
Example 2
Source File: RedisConfig.java From admin-plus with Apache License 2.0 | 5 votes |
@Bean public CacheManager cacheManager() { RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder .fromConnectionFactory(lettuceConnectionFactory); @SuppressWarnings("serial") Set<String> cacheNames = new HashSet<String>() { { add("codeNameCache"); } }; builder.initialCacheNames(cacheNames); return builder.build(); }
Example 3
Source File: RedisConfig.java From pre with GNU General Public License v3.0 | 5 votes |
@Bean public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager .RedisCacheManagerBuilder .fromConnectionFactory(redisConnectionFactory); return builder.build(); }
Example 4
Source File: RedisConfig.java From FEBS-Security with Apache License 2.0 | 5 votes |
@Bean public CacheManager cacheManager(RedisConnectionFactory redisConnectionFactory) { RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager .RedisCacheManagerBuilder .fromConnectionFactory(redisConnectionFactory); return builder.build(); }
Example 5
Source File: RedisCacheAutoConfiguration.java From loc-framework with MIT License | 4 votes |
@Bean public RedisCacheManager getRedisCacheManager(RedisConnectionFactory redisConnectionFactory) { CustomRedisCacheWriter customRedisCacheWriter = new CustomRedisCacheWriter( RedisCacheWriter.lockingRedisCacheWriter(redisConnectionFactory)); RedisCacheManager.RedisCacheManagerBuilder builder = RedisCacheManager.RedisCacheManagerBuilder .fromCacheWriter(customRedisCacheWriter).cacheDefaults(determineConfiguration()); List<String> cacheNames = this.cacheProperties.getCacheNames(); if (!cacheNames.isEmpty()) { try { LocCustomCacheProperties customCacheProperties = resolverSetting( LocCustomCacheProperties.class, this.environment.getPropertySources()); Map<String, RedisCacheConfiguration> map = Maps.newHashMap(); cacheNames.forEach(name -> { LocCacheProperties locCacheProperties = customCacheProperties.getCustomCache().get(name); RedisCacheConfiguration redisCacheConfiguration = determineConfiguration(); if (locCacheProperties.getTimeToLive() != null) { redisCacheConfiguration = redisCacheConfiguration .entryTtl(locCacheProperties.getTimeToLive()); } if (locCacheProperties.getKeyPrefix() != null) { redisCacheConfiguration = redisCacheConfiguration .prefixKeysWith(locCacheProperties.getKeyPrefix()); } if (!locCacheProperties.isCacheNullValues()) { redisCacheConfiguration = redisCacheConfiguration.disableCachingNullValues(); } if (!locCacheProperties.isUseKeyPrefix()) { redisCacheConfiguration = redisCacheConfiguration.disableKeyPrefix(); } map.put(name, redisCacheConfiguration); }); builder.withInitialCacheConfigurations(map); } catch (FatalBeanException e) { log.warn("may be not config customCache properties"); } } return builder.build(); }