简体   繁体   English

从HTTP请求或Rest GET缓存结果

[英]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. 我需要做一个简单的缓存,当在该方法上传递相同的Account ID时,而不是再次调用其余客户端。 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. 根据您传输的数据量, HttpSession对象在您的情况下可能会很有用。 http://docs.oracle.com/javaee/1.3/api/javax/servlet/http/HttpSession.html http://docs.oracle.com/javaee/1.3/api/javax/servlet/http/HttpSession.html

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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