Search in sources :

Example 1 with QueryTagFilter

use of lucee.runtime.cache.util.QueryTagFilter in project Lucee by lucee.

the class CacheClear method _call.

private static double _call(PageContext pc, Object filterOrTags, String cacheName) throws PageException {
    try {
        Object filter = FILTER;
        // tags
        boolean isArray = false;
        String dsn = null;
        if ((isArray = Decision.isArray(filterOrTags)) || Decision.isStruct(filterOrTags)) {
            // read tags from collection and datasource (optional)
            String[] tags;
            if (!isArray) {
                Struct sct = Caster.toStruct(filterOrTags);
                Array arr = Caster.toArray(sct.get("tags", null), null);
                if (arr == null)
                    throw new FunctionException(pc, "CacheClear", 1, "tags", "if you pass the tags within a struct, that struct need to have a key [tags] containing the tags in an array.");
                tags = ListUtil.toStringArray(arr);
                dsn = Caster.toString(sct.get(KeyConstants._datasource, null), null);
            } else {
                tags = ListUtil.toStringArray(Caster.toArray(filterOrTags));
            }
            // get default datasource
            if (StringUtil.isEmpty(dsn)) {
                Object tmp = pc.getApplicationContext().getDefDataSource();
                dsn = tmp instanceof CharSequence ? Caster.toString(tmp, null) : null;
            }
            filter = new QueryTagFilter(tags, StringUtil.isEmpty(dsn) ? null : dsn);
        } else // filter
        {
            String strFilter = Caster.toString(filterOrTags);
            if (CacheGetAllIds.isFilter(strFilter))
                filter = new WildCardFilter(strFilter, true);
        }
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        if (filter instanceof CacheKeyFilter)
            return cache.remove((CacheKeyFilter) filter);
        return cache.remove((CacheEntryFilter) filter);
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : QueryTagFilter(lucee.runtime.cache.util.QueryTagFilter) FunctionException(lucee.runtime.exp.FunctionException) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Struct(lucee.runtime.type.Struct) Array(lucee.runtime.type.Array) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) CacheKeyFilter(lucee.commons.io.cache.CacheKeyFilter) Cache(lucee.commons.io.cache.Cache)

Aggregations

Cache (lucee.commons.io.cache.Cache)1 CacheKeyFilter (lucee.commons.io.cache.CacheKeyFilter)1 QueryTagFilter (lucee.runtime.cache.util.QueryTagFilter)1 WildCardFilter (lucee.runtime.cache.util.WildCardFilter)1 FunctionException (lucee.runtime.exp.FunctionException)1 PageException (lucee.runtime.exp.PageException)1 Array (lucee.runtime.type.Array)1 Struct (lucee.runtime.type.Struct)1