简体   繁体   中英

Caching results from an HTTP request or Rest GET

I have this method:

@Service // org.jboss.errai.bus.server.annotations.Service
class StuffServiceImpl implements StuffService {
    @Override
    public List<String> getStuffForUser(Account account) {
        return restClient.getStuffByAccount(account);
    }  
}

Which is called many times during the lifetime of an application. I need to do a simple caching, where when the the same Account id is passed on the method, instead of calling the rest client again. It will just get the result from the cache.

I don't want to manually create a cache system, and would like to just use existing caching frameworks that is applicable.

And also, there should be a way to flush the "cache" for this method, which will be used during when the user logs out for example.

Depending on the amount of data you are transferring, the HttpSession object might be useful in your situation. http://docs.oracle.com/javaee/1.3/api/javax/servlet/http/HttpSession.html

您可以使用memcahe技术或Redis,这些都很简单。您可以灵活地刷新缓存。

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