- 我已在@配置文件中配置了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;
}
-
我还有一个名为Adapter的类,在其中我进行了
resttemplate.exchange(uri,entity,method,response)
的调用,并使response(partnerinfo)
投入使用。 -
从REST API调用获得响应后,我需要在使用
@Cacheable(value = "partnersCache",key = "#apiKey")
的服务类中进行一些操作,以便不再对上述REST调用进行任何进一步的调用。在ehcache.xml
中提到
服务类别:
@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通话,不确定我错过了什么。
预先感谢