Search in sources :

Example 1 with CacheHandlerCollection

use of lucee.runtime.cache.tag.CacheHandlerCollection 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]");
}
Also used : ApplicationException(lucee.runtime.exp.ApplicationException) CacheHandlerCollection(lucee.runtime.cache.tag.CacheHandlerCollection) CacheResourceProvider(lucee.commons.io.res.type.cache.CacheResourceProvider) Cache(lucee.commons.io.cache.Cache)

Aggregations

Cache (lucee.commons.io.cache.Cache)1 CacheResourceProvider (lucee.commons.io.res.type.cache.CacheResourceProvider)1 CacheHandlerCollection (lucee.runtime.cache.tag.CacheHandlerCollection)1 ApplicationException (lucee.runtime.exp.ApplicationException)1