0

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 ?

2
  • Why do you need to add sync. This has quite a cost and I see no reason to use it in your case. Commented Jan 21, 2019 at 9:16
  • inside the method, there is a call on a REST service, which takes about 2s. Until the response returns, we want to block all other threads with the same id. Commented Feb 27, 2019 at 11:30

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.