Package org.xlightweb.IHttpCache

Examples of org.xlightweb.IHttpCache.ICacheEntry


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

                        ce.revalidate(exchange, validationHdl);
                    }
                 
                // .. revalidation is not required
                } else {
                    countCacheHit++;
                    statistics.addHit();
                    IHttpResponse resp = ce.newResponse();
                    resp.setHeader(XHEADER_NAME, "HIT  (xLightweb)");
                    resp.setAttribute(CACHE_HIT, "HIT");

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


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

                        ce.revalidate(exchange, validationHdl);
                    }
                 
                // .. revalidation is not required
                } else {
                    countCacheHit++;
                    statistics.addHit();
                    IHttpResponse resp = ce.newResponse();
                    resp.setHeader(XHEADER_NAME, "HIT  (xLightweb)");
                    resp.setAttribute(CACHE_HIT, "HIT");

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

TOP

Related Classes of org.xlightweb.IHttpCache.ICacheEntry

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.