Package org.xlightweb.client.HttpCache

Examples of org.xlightweb.client.HttpCache.CacheEntry


      }
     
        
      // handle caching
      try {
            CacheEntry ce = cache.get(request, minFresh);
            // is cache entry valid?
            if (ce != null) {
               
                if ((maxOld != null) && (ce.isAfter(maxOld))) {
                    forwardForCache(exchange);
                    return;
                }
               
                // must revalidate?
                if (ce.mustRevalidate(minFresh)) {
                   
                    if (isOnlyIfCached) {
                        countCacheMiss++;
                        exchange.sendError(504);
                       
                    } else {
                        IValidationHandler validationHdl = new IValidationHandler() {
                           
                            public void onRevalidated(boolean isNotModified, CacheEntry ce) {
                               
                                if (isNotModified) {
                                    try {
                                        countCacheHit++;
                                        IHttpResponse resp = ce.newResponse();
                                        resp.setHeader(XHEADER_NAME, "HIT - revalidated (xLightweb)");
                                        exchange.send(resp);
                                    } catch (IOException ioe) {
                                        exchange.sendError(ioe);
                                    }
                                } else  {
                                    try {
                                        countCacheMiss++;
                                        IHttpResponse resp = ce.newResponse();
                                        exchange.send(resp);
                                    } catch (IOException ioe) {
                                        exchange.sendError(ioe);
                                    }
                                }
                            }
                           
                            public void onException(IOException ioe) {
                                exchange.sendError(ioe);
                            }
                           
                        };

                        ce.revalidate(validationHdl);
                    }
                 
                // no, return cached response
                } else {
                    countCacheHit++;
                    IHttpResponse resp = ce.newResponse();
                    resp.setHeader(XHEADER_NAME, "HIT  (xLightweb)");

                    exchange.send(resp);
                }
              
View Full Code Here

TOP

Related Classes of org.xlightweb.client.HttpCache.CacheEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.