use of lucee.commons.io.res.type.cache.CacheResourceProvider in project Lucee by lucee.
the class ObjectCache method _doStartTag.
public void _doStartTag() throws PageException, IOException {
CacheHandlerCollection factory = null;
Cache cache = null;
if (type == TYPE_FUNCTION)
factory = pageContext.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_FUNCTION, null);
else if (type == TYPE_INCLUDE)
factory = pageContext.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_INCLUDE, null);
else if (type == TYPE_QUERY)
factory = pageContext.getConfig().getCacheHandlerCollection(Config.CACHE_TYPE_QUERY, null);
else if (type == TYPE_RESOURCE) {
cache = CacheUtil.getDefault(pageContext, Config.CACHE_TYPE_RESOURCE, null);
// no specific cache is defined, get default default cache
if (cache == null) {
// get cache resource provider
CacheResourceProvider crp = null;
ResourceProvider[] providers = ResourcesImpl.getGlobal().getResourceProviders();
for (int i = 0; i < providers.length; i++) {
if (providers[i].getScheme().equals("ram") && providers[i] instanceof CacheResourceProvider) {
crp = (CacheResourceProvider) providers[i];
}
}
if (crp == null)
throw new ApplicationException(Constants.NAME + " was not able to load the Ram Resource Provider");
// get cache from resource provider
cache = crp.getCache();
}
} else if (type == TYPE_OBJECT) {
// throws a exception if not explicitly defined
cache = CacheUtil.getDefault(pageContext, Config.CACHE_TYPE_OBJECT);
} else if (type == TYPE_TEMPLATE) {
// throws a exception if not explicitly defined
cache = CacheUtil.getDefault(pageContext, Config.CACHE_TYPE_TEMPLATE);
}
// Clear
if (action.equalsIgnoreCase("clear")) {
if (filter == null) {
if (cache != null)
cache.remove(CacheKeyFilterAll.getInstance());
else
factory.clear(pageContext);
} else {
if (cache != null)
CacheHandlerCollectionImpl.clear(pageContext, cache, filter);
else
factory.clear(pageContext, filter);
}
} else // Size
if (action.equalsIgnoreCase("size")) {
int size = 0;
if (cache != null)
size = cache.keys().size();
else
size = factory.size(pageContext);
pageContext.setVariable(result, Caster.toDouble(size));
} else
throw new ApplicationException("attribute action has an invalid value [" + action + "], valid is only [clear,size]");
}
Aggregations