简体   繁体   中英

How can I cache a rest Request using java?

I'm working on a Java project using Spring Integration for consuming a REST webservice just for retrieving information. The web service responses change once a month. The amount of requests is huge, so I want to decrease the network traffic. Is it possible to do this using a cache proxy or is there any better tool for this task?

If you are using Spring you can use Spring Cache . That and a CacheManager that expires after 30 days. If you have Java 8 you can use Caffeine:

@Bean
public CacheManager cacheManager() {

   final CaffeineCacheManager manager = new CaffeineCacheManager();
   final Caffeine<Object, Object> caffeineBuilder = Caffeine.newBuilder()
                         .expireAfterWrite(30, TimeUnit.DAYS);
   manager.setCaffeine(caffeineBuilder);
   return manager;

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM