/** * Get the time to live for a page, in milliseconds * * @return time to live in milliseconds */ protected long calculateTimeToLiveMilliseconds() { if (blockingCache.isDisabled()) { return -1; } else { CacheConfiguration cacheConfiguration = blockingCache.getCacheConfiguration(); if (cacheConfiguration.isEternal()) { return ONE_YEAR_IN_MILLISECONDS; } else { return cacheConfiguration.getTimeToLiveSeconds() * MILLISECONDS_PER_SECOND; } } }
/** * {@inheritDoc} * * @param request {@inheritDoc} * @param response {@inheritDoc} * @param chain {@inheritDoc} * @return {@inheritDoc} * @throws AlreadyGzippedException {@inheritDoc} * @throws Exception {@inheritDoc} */ protected PageInfo buildPage(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws AlreadyGzippedException, Exception { // Invoke the next entity in the chain final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); final GenericResponseWrapper wrapper = new GenericResponseWrapper(response, outstr); chain.doFilter(request, wrapper); wrapper.flush(); long timeToLiveSeconds = blockingCache.getCacheConfiguration().getTimeToLiveSeconds(); // Return the page info return new PageInfo(wrapper.getStatus(), wrapper.getContentType(), wrapper.getCookies(), outstr.toByteArray(), false, timeToLiveSeconds, wrapper.getAllHeaders()); }
@Override protected PageInfo buildPage( HttpServletRequest request, HttpServletResponse response, FilterChain chain ) throws Exception { // Invoke the next entity in the chain final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); final GenericResponseWrapper wrapper = new GenericResponseWrapper( response, outstr ); chain.doFilter( request, wrapper ); wrapper.flush(); final long timeToLiveSeconds = blockingCache.getCacheConfiguration() .getTimeToLiveSeconds(); boolean cacheable = true; for ( Header<? extends Serializable> header : wrapper.getAllHeaders() ) { if ( HeaderConstants.HEADER_CACHE_CONTROL.equals( header.getName() ) && HeaderConstants.CACHE_NO_CACHE.equals( header.getValue() ) ) { cacheable = false; } } // Return the page info return new CustomPageInfo( wrapper.getStatus(), wrapper.getContentType(), wrapper.getCookies(), outstr.toByteArray(), true, timeToLiveSeconds, wrapper.getAllHeaders(), cacheable ); } }
/** * Builds the PageInfo object by passing the request along the filter chain * * @param request * @param response * @param chain * @return a Serializable value object for the page or page fragment * @throws AlreadyGzippedException * if an attempt is made to double gzip the body * @throws Exception */ protected PageInfo buildPage(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws AlreadyGzippedException, Exception { // Invoke the next entity in the chain final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); final GenericResponseWrapper wrapper = new GenericResponseWrapper( response, outstr); chain.doFilter(request, wrapper); wrapper.flush(); long timeToLiveSeconds = blockingCache.getCacheConfiguration() .getTimeToLiveSeconds(); // Return the page info return new PageInfo(wrapper.getStatus(), wrapper.getContentType(), wrapper.getCookies(), outstr.toByteArray(), true, timeToLiveSeconds, wrapper.getAllHeaders()); }