springboot中的Rest api调用未发生缓存(Ehcache)

  1. 我已在@配置文件中配置了EHCache
    下面是配置文件:
@EnableCaching
@Configuration
public class CacheclientConfig {

    @Bean
    public CacheManager cacheManager(){
        return new EhCacheCacheManager(cacheManagerFactory().getObject());
    }

    @Bean
    public EhCacheManagerFactoryBean cacheManagerFactory(){
        EhCacheManagerFactoryBean bean = new EhCacheManagerFactoryBean();
        bean.setConfigLocation(new ClasspathResource("ehcache.xml"));
        bean.setShared(true);
        return bean;
    }
  1. 我还有一个名为Adapter的类,在其中我进行了resttemplate.exchange(uri,entity,method,response)的调用,并使response(partnerinfo)投入使用。

  2. 从REST API调用获得响应后,我需要在使用@Cacheable(value = "partnersCache",key = "#apiKey")的服务类中进行一些操作,以便不再对上述REST调用进行任何进一步的调用。在ehcache.xml

  3. 中提到

服务类别:

@Cacheable(value = "partnersCache",key = "#apiKey")
private List<PartnerInfo> checkPartnerInfo(HttpHeaders headers) throws Exception {
    List<PartnerInfo> partners = new ArrayList<PartnerInfo>();
    partners  = getPartnerInfoAdapter.getPartnerInfo().getBody();
    return partners  ;
}

getPartnerInfoAdapter类:

restTemplate.exchange(builder.build().toUri(),HttpMethod.GET,Object[].class);

ehcache.xml

我已经使用partnerCache作为配置文件中配置的ehcache.xml中的缓存名称

但是通话要经常进行REST通话,不确定我错过了什么。

预先感谢

peak288 回答:springboot中的Rest api调用未发生缓存(Ehcache)

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3159180.html

大家都在问