Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
有没有办法在spring中只为一个方法启用缓存?_Spring_Spring Cache - Fatal编程技术网

有没有办法在spring中只为一个方法启用缓存?

有没有办法在spring中只为一个方法启用缓存?,spring,spring-cache,Spring,Spring Cache,我有一个spring项目,在其中我在方法级别实现了缓存。现在我需要停止整个项目的缓存。我用旗子阻止它,设置为false 现在我只想为一个方法启用缓存。有没有办法只为一个方法启用缓存 @Cacheable(value = CacheHelper.APPLICATION_CACHE_NAME, key = "T(ca.sunlife.grs.core.cache.CacheHelper).generateApplicationCacheKey(T(ca.sunlife.grs.core.cache.

我有一个spring项目,在其中我在方法级别实现了缓存。现在我需要停止整个项目的缓存。我用旗子阻止它,设置为false

现在我只想为一个方法启用缓存。有没有办法只为一个方法启用缓存

@Cacheable(value = CacheHelper.APPLICATION_CACHE_NAME, key = "T(ca.sunlife.grs.core.cache.CacheHelper).generateApplicationCacheKey(T(ca.sunlife.grs.core.cache.CacheKey).CACHE_GET_MEMBER,#request.getClientId() + #request.getPlanId() + #request.getMemberNumber() +#request.getMemberIndicator())", unless = "#result== null")
public GetMemberMqResponse getMemberWithCache(GetMemberRequest request) throws Exception {
    GetMemberMqRequest mqRequest = getMemberDomainToMqMapper.toMqRequest(request);
    GrsLogger.info(this, "MQRequest is:" + mqRequest.getRequestString());
    return getMemberMqResponseParser.parseMqResponse(grsMqTransactionOrMockRunner.run(mqRequest));
}

您可以将
@Cacheable
仅放在要缓存的方法上,并将其从不希望缓存的方法中删除。

您可以使用和驱动器,使用Spring启用了哪个CacheManager

公共类NoOpCacheManager扩展对象实现CacheManager

一种基本的无操作CacheManager实现,适用于禁用缓存,通常用于在没有实际备份存储的情况下备份缓存声明。 将只接受缓存中的任何项,而不是实际存储它们


有没有其他方法可以阻止它,比如通过使用任何注释我们可以阻止它。我不确定,但我认为没有其他方法,如果在项目或类级别启用缓存,则必须在方法级别禁用它。此答案没有解决如何为整个项目禁用缓存的问题。很抱歉@LucasP,但问题是如何仅为一个方法启用缓存,正如您可以阅读的
现在我需要仅为一个方法启用缓存一种方法。有没有办法只为一种方法启用缓存
@Bean
public CacheManager cacheManager() {
    return new CaffeineCacheManager(); //Example implementation
}

@Bean
@Profile("noCaching")
@Primary
public CacheManager noOpCacheManager() {
    return new NoOpCacheManager();
}