Search in sources :

Example 1 with CacheItem

use of lucee.runtime.cache.legacy.CacheItem in project Lucee by lucee.

the class Cache method doServerCache.

private void doServerCache() throws IOException, PageException {
    if (hasBody)
        hasBody = !StringUtil.isEmpty(body);
    // call via cfcache disable debugger output
    if (pageContext.getConfig().debug())
        pageContext.getDebugger().setOutput(false);
    HttpServletResponse rsp = pageContext.getHttpServletResponse();
    // generate cache resource matching request object
    CacheItem ci = generateCacheResource(null, false);
    // use cached resource
    if (ci.isValid(timespan)) {
        // if(isOK(cacheResource)){
        if (pageContext.getHttpServletResponse().isCommitted())
            return;
        OutputStream os = null;
        try {
            ci.writeTo(os = getOutputStream(), ReqRspUtil.getCharacterEncoding(pageContext, rsp).name());
        // IOUtil.copy(is=cacheResource.getInputStream(),os=getOutputStream(),false,false);
        } finally {
            IOUtil.flushEL(os);
            IOUtil.closeEL(os);
            ((PageContextImpl) pageContext).getRootOut().setClosed(true);
        }
        throw new Abort(Abort.SCOPE_REQUEST);
    }
    // call page again and
    // MetaData.getInstance(getDirectory()).add(ci.getName(), ci.getRaw());
    PageContextImpl pci = (PageContextImpl) pageContext;
    pci.getRootOut().doCache(ci);
}
Also used : Abort(lucee.runtime.exp.Abort) OutputStream(java.io.OutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) CacheItem(lucee.runtime.cache.legacy.CacheItem) PageContextImpl(lucee.runtime.PageContextImpl)

Aggregations

OutputStream (java.io.OutputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 PageContextImpl (lucee.runtime.PageContextImpl)1 CacheItem (lucee.runtime.cache.legacy.CacheItem)1 Abort (lucee.runtime.exp.Abort)1