use of lucee.runtime.cache.tag.include.IncludeCacheItem in project Lucee by lucee.
the class PageContextImpl method _doInclude.
// IMPORTANT!!! we do not getCachedWithin in this method, because Modern|ClassicAppListener is calling this method and in this case it should not be used
public void _doInclude(PageSource[] sources, boolean runOnce, Object cachedWithin) throws PageException {
if (cachedWithin == null) {
_doInclude(sources, runOnce);
return;
}
// ignore call when runonce an it is not first call
if (runOnce) {
Page currentPage = PageSourceImpl.loadPage(this, sources);
if (runOnce && includeOnce.contains(currentPage.getPageSource()))
return;
}
// get cached data
String cacheId = CacheHandlerCollectionImpl.createId(sources);
CacheHandler cacheHandler = config.getCacheHandlerCollection(Config.CACHE_TYPE_INCLUDE, null).getInstanceMatchingObject(cachedWithin, null);
if (cacheHandler instanceof CacheHandlerPro) {
CacheItem cacheItem = ((CacheHandlerPro) cacheHandler).get(this, cacheId, cachedWithin);
if (cacheItem instanceof IncludeCacheItem) {
try {
write(((IncludeCacheItem) cacheItem).getOutput());
return;
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
} else if (cacheHandler != null) {
// TODO this else block can be removed when all cache handlers implement CacheHandlerPro
CacheItem cacheItem = cacheHandler.get(this, cacheId);
if (cacheItem instanceof IncludeCacheItem) {
try {
write(((IncludeCacheItem) cacheItem).getOutput());
return;
} catch (IOException e) {
throw Caster.toPageException(e);
}
}
}
// cached item not found, process and cache result if needed
long start = System.nanoTime();
BodyContent bc = pushBody();
try {
_doInclude(sources, runOnce);
String out = bc.getString();
if (cacheHandler != null) {
CacheItem cacheItem = new IncludeCacheItem(out, ArrayUtil.isEmpty(sources) ? null : sources[0], System.nanoTime() - start);
cacheHandler.set(this, cacheId, cachedWithin, cacheItem);
return;
}
} finally {
BodyContentUtil.flushAndPop(this, bc);
}
}
Aggregations