Spring Cache处理Cache-Control = no-cache

时间:2019-01-16 06:41:24

标签: spring caching cache-control spring-cache

在我们的REST服务中,我们将redis与spring缓存一起使用。我们需要处理一些带有标头的请求:Cache-control = no-cache。这些请求不应从缓存中接收数据。
我们为@ cacheStatusServiceImpl.isNoCacheMode()使用条件来决定是否应使用缓存。
示例:

    @Caching(put = {@CachePut(value = CacheNameConstants.MY_CACHE,
        key = "#id", condition = "@cacheStatusServiceImpl.isNoCacheMode()")},
        cacheable = {@Cacheable(value = CacheNameConstants.MY_CACHE,
                key = "#id", condition = "!@cacheStatusServiceImpl.isNoCacheMode()")})

现在我们需要添加sync = true,但是sync不能与@CachePut结合使用,因此不能使用之前的代码。
我尝试使用自定义的cacheResolver,我看到了方法参数,具有cacheName,但是无法访问键值。 CacheAspectSupprt具有用于生成密钥的私有方法,该方法无法访问。 有什么想法如何处理无缓存吗?

0 个答案:

没有答案