It would be nice if there was a pluggable mechanism (i.e. strategy interface) in order to intercept put/get to the underlying caches that the CacheManager interacts with.
This would allow for transforming read/writes in order to decrypt/encrypt the values.
There seems to be another user requesting the same at SO: https://stackoverflow.com/questions/46478798/how-to-write-custom-interceptor-for-spring-cachecachable
Comment From: snicoll
Thanks for the suggestion but we need to draw a line somewhere as the cache support in Spring Framework can't abstract the actual cache libraries too much. You already have that contract using a delegation pattern and a CacheResolver
to return a wrapped Cache
that does what you want.
Comment From: davidkarlsen
Well, it's not so much about abstracting the underlying cache, but transforming the value that's set into the cache. Rather than resolving the cache (which is already fine as it is) - maybe https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/Cache.ValueWrapper.html with a set() in addition to the get() could be a way to go?
Comment From: snicoll
Well, it's not so much about abstracting the underlying cache, but transforming the value that's set into the cache.
Yes but that contract already exists in the Cache
interface and creating yet another contract has a maintenance cost that isn't worth it.
maybe https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/cache/Cache.ValueWrapper.html with a set() in addition to the get() could be a way to go?
Certainly not, ValueWrapper
must be immutable.