use of lucee.runtime.cache.tag.udf.UDFCacheItem in project Lucee by lucee.
the class UDFImpl method _callCachedWithin.
private Object _callCachedWithin(PageContext pc, Collection.Key calledName, Object[] args, Struct values, boolean doIncludePath) throws PageException {
PageContextImpl pci = (PageContextImpl) pc;
Object cachedWithin = getCachedWithin(pc);
String cacheId = CacheHandlerCollectionImpl.createId(this, args, values);
CacheHandler cacheHandler = pc.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_FUNCTION, null).getInstanceMatchingObject(getCachedWithin(pc), null);
if (cacheHandler instanceof CacheHandlerPro) {
CacheItem cacheItem = ((CacheHandlerPro) cacheHandler).get(pc, cacheId, cachedWithin);
if (cacheItem instanceof UDFCacheItem) {
UDFCacheItem entry = (UDFCacheItem) cacheItem;
try {
pc.write(entry.output);
} catch (IOException e) {
throw Caster.toPageException(e);
}
return entry.returnValue;
}
} else if (cacheHandler != null) {
// TODO this else block can be removed when all cache handlers implement CacheHandlerPro
CacheItem cacheItem = cacheHandler.get(pc, cacheId);
if (cacheItem instanceof UDFCacheItem) {
UDFCacheItem entry = (UDFCacheItem) cacheItem;
// if(entry.creationdate+properties.cachedWithin>=System.currentTimeMillis()) {
try {
pc.write(entry.output);
} catch (IOException e) {
throw Caster.toPageException(e);
}
return entry.returnValue;
// }
// cache.remove(id);
}
}
// cached item not found, process and cache result if needed
long start = System.nanoTime();
// execute the function
BodyContent bc = pci.pushBody();
try {
Object rtn = _call(pci, calledName, args, values, doIncludePath);
if (cacheHandler != null) {
String out = bc.getString();
cacheHandler.set(pc, cacheId, cachedWithin, new UDFCacheItem(out, rtn, getFunctionName(), getSource(), System.nanoTime() - start));
}
return rtn;
} finally {
BodyContentUtil.flushAndPop(pc, bc);
}
}
Aggregations