I am using Spring Data Cache using Redis as the cache manager. The config is like:
return RedisCacheManager.builder(redisConnectionFactory) .cacheDefaults( RedisCacheConfiguration.defaultCacheConfig() .serializeKeysWith(SerializationPair.fromSerializer(RedisSerializer.string())) .serializeValuesWith(SerializationPair.fromSerializer(RedisSerializer.json())) ) .build()
Let's imagine a very naive example using spring data cache:
@Cacheable(...)MyPOJO compute() { ... }
However, the RedisSerializer.json()
is indeed a GenericJackson2JsonRedisSerializer
. Thus, IMHO it will store things like {"hello":"world","@class":"com.my.name.some.package.MyPOJO"}
. That @class: ...
part is quite long and a waste of precious memory in Redis. Moreover, IMHO Spring Data Cache should be smart enough to realize that the value type is indeed MyPOJO
, so it should not need to store that "@class"
.
Thus my question is: How to avoid storing class names in serialized JSON which waste lots of space, in Spring Data Cache + Redis CacheManager?
Thanks for any suggestions!