1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| @Bean public CacheManager cacheManager(RedisConnectionFactory connectionFactory) { RedisSerializationContext.SerializationPair serializationPair = RedisSerializationContext.SerializationPair.fromSerializer(getRedisSerializer()); RedisCacheConfiguration redisCacheConfiguration = RedisCacheConfiguration.defaultCacheConfig() .entryTtl(Duration.ofHours(1)).serializeKeysWith(serializationPair) .serializeValuesWith(serializationPair); return RedisCacheManager .builder(RedisCacheWriter.nonLockingRedisCacheWriter(connectionFactory)) .cacheDefaults(redisCacheConfiguration).build(); }
private RedisSerializer<Object> getRedisSerializer(){ return new GenericFastJsonRedisSerializer(); }
|