Search in sources :

Example 1 with WildCardFilter

use of lucee.runtime.cache.util.WildCardFilter 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)

Example 2 with WildCardFilter

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

the class CacheGetAllIds method call.

public static Array call(PageContext pc, String filter, String cacheName) throws PageException {
    try {
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        List<String> keys = isFilter(filter) ? cache.keys(new WildCardFilter(filter, true)) : cache.keys();
        Iterator<String> it = keys.iterator();
        Array arr = new ArrayImpl();
        while (it.hasNext()) {
            arr.append(it.next());
        }
        return arr;
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : Array(lucee.runtime.type.Array) ArrayImpl(lucee.runtime.type.ArrayImpl) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache)

Example 3 with WildCardFilter

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

the class CacheGetAll method call.

public static Struct call(PageContext pc, String filter, String cacheName) throws PageException {
    try {
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        List<CacheEntry> entries = CacheGetAllIds.isFilter(filter) ? cache.entries(new WildCardFilter(filter, true)) : cache.entries();
        Iterator<CacheEntry> it = entries.iterator();
        Struct sct = new StructImpl();
        CacheEntry entry;
        while (it.hasNext()) {
            entry = it.next();
            sct.setEL(KeyImpl.getInstance(entry.getKey()), entry.getValue());
        }
        return sct;
    } catch (Exception e) {
        throw Caster.toPageException(e);
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) CacheEntry(lucee.commons.io.cache.CacheEntry) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache) Struct(lucee.runtime.type.Struct)

Example 4 with WildCardFilter

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

the class CacheEngine method list.

public Struct list(String filter) {
    Struct sct = new StructImpl();
    try {
        List entries;
        if (Util.isEmpty(filter))
            entries = cache.entries();
        else
            entries = cache.entries(new WildCardFilter(filter, false));
        Iterator it = entries.iterator();
        CacheEntry entry;
        while (it.hasNext()) {
            entry = (CacheEntry) it.next();
            sct.setEL(entry.getKey(), entry.getValue());
        }
    } catch (Exception e) {
        SystemOut.printDate(e);
    }
    return sct;
}
Also used : StructImpl(lucee.runtime.type.StructImpl) Iterator(java.util.Iterator) List(java.util.List) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) CacheEntry(lucee.commons.io.cache.CacheEntry) IOException(java.io.IOException) CacheException(lucee.commons.io.cache.exp.CacheException) Struct(lucee.runtime.type.Struct)

Aggregations

WildCardFilter (lucee.runtime.cache.util.WildCardFilter)4 Cache (lucee.commons.io.cache.Cache)3 FunctionException (lucee.runtime.exp.FunctionException)3 PageException (lucee.runtime.exp.PageException)3 Struct (lucee.runtime.type.Struct)3 CacheEntry (lucee.commons.io.cache.CacheEntry)2 Array (lucee.runtime.type.Array)2 StructImpl (lucee.runtime.type.StructImpl)2 IOException (java.io.IOException)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CacheKeyFilter (lucee.commons.io.cache.CacheKeyFilter)1 CacheException (lucee.commons.io.cache.exp.CacheException)1 QueryTagFilter (lucee.runtime.cache.util.QueryTagFilter)1 ArrayImpl (lucee.runtime.type.ArrayImpl)1