Client-side caching

With server-side caching, the client will still have to hit the target resource. When the bandwidth is a constraint and there is a requirement to save network-round trips, it makes sense to enable caching at the client side when the consuming system has enough resources required for caching. The HTTP 1.1 protocol specification defines the guidelines around client-side caching with control parameters such as cache-control headers to decide about caching the server response and the cache-expiry mechanisms. 

Following the HTTP specification, RESTEasy provides the BrowserCacheFeature API  for implementing client-side caching, as shown ahead:

//Enabling Client-Side Caching 
public DepartmentServiceClient(){
webTarget = (ResteasyWebTarget) ClientBuilder.newClient().target(BASE_URI);

//Step1: Construct an instance of RESTEasy LightweightBrowserCache
LightweightBrowserCache cache = new LightweightBrowserCache();
//Step2: Default 2 MB of data is the max size, override as relevant
cache.setMaxBytes(20);
//Step3: Apply the BrowserCacheFeature to the target resource to enable caching
BrowserCacheFeature cacheFeature = new BrowserCacheFeature();
cacheFeature.setCache(cache);
webTarget.register(cacheFeature);
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.234.150