In our REST service we are using redis with spring cache. We need to handle some requests with header: Cache-control=no-cache. These requests should not recieve the data from cache.
We use a condition for @cacheStatusServiceImpl.isNoCacheMode() to decide if the cache should be used or not.
Example:
@Caching(put = {@CachePut(value = CacheNameConstants.MY_CACHE,
key = "#id", condition = "@cacheStatusServiceImpl.isNoCacheMode()")},
cacheable = {@Cacheable(value = CacheNameConstants.MY_CACHE,
key = "#id", condition = "[email protected]()")})
Now we need to add sync=true, but sync can't be used in combination with @CachePut, so the previous code can't be used.
I have tried to use a custom cacheResolver, I see the methods parameters, have the cacheName, but can't access the key value. CacheAspectSupprt has a private method for generating the key, which I can't access.
Any ideas how to handle the no-cache ?
sync
. This has quite a cost and I see no reason to use it in your case.