Search in sources :

Example 6 with CacheEntry

use of lucee.commons.io.cache.CacheEntry in project Lucee by lucee.

the class TimespanCacheHandler method clean.

@Override
public void clean(PageContext pc) {
    try {
        Cache c = getCache(pc);
        List<CacheEntry> entries = c.entries();
        if (entries.size() < 100)
            return;
        Iterator<CacheEntry> it = entries.iterator();
        while (it.hasNext()) {
            // touch them to makes sure the cache remove them, not really good, cache must do this by itself
            it.next();
        }
    } catch (IOException ioe) {
    }
}
Also used : IOException(java.io.IOException) CacheEntry(lucee.commons.io.cache.CacheEntry) Cache(lucee.commons.io.cache.Cache) RamCache(lucee.runtime.cache.ram.RamCache)

Example 7 with CacheEntry

use of lucee.commons.io.cache.CacheEntry in project Lucee by lucee.

the class CacheStorageScopeCleaner method clean.

private void clean(CacheConnection cc, ConfigWebImpl config) throws IOException {
    Cache cache = cc.getInstance(config);
    int len = filter.length(), index;
    List<CacheEntry> entries = cache.entries(filter);
    CacheEntry ce;
    long expires;
    String key, appname, cfid;
    if (entries.size() > 0) {
        Iterator<CacheEntry> it = entries.iterator();
        while (it.hasNext()) {
            ce = it.next();
            Date lm = ce.lastModified();
            long time = lm != null ? lm.getTime() : 0;
            expires = time + ce.idleTimeSpan() - StorageScopeCache.SAVE_EXPIRES_OFFSET;
            if (expires <= System.currentTimeMillis()) {
                key = ce.getKey().substring(len);
                index = key.indexOf(':');
                cfid = key.substring(0, index);
                appname = key.substring(index + 1);
                if (listener != null)
                    listener.doEnd(engine, this, appname, cfid);
                info("remove " + strType + "/" + appname + "/" + cfid + " from cache " + cc.getName());
                engine.remove(type, appname, cfid);
                cache.remove(ce.getKey());
            }
        }
    }
// engine.remove(type,appName,cfid);
// return (Struct) cache.getValue(key,null);
}
Also used : CacheEntry(lucee.commons.io.cache.CacheEntry) Date(java.util.Date) StorageScopeCache(lucee.runtime.type.scope.storage.StorageScopeCache) Cache(lucee.commons.io.cache.Cache)

Example 8 with CacheEntry

use of lucee.commons.io.cache.CacheEntry 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 9 with CacheEntry

use of lucee.commons.io.cache.CacheEntry 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)

Example 10 with CacheEntry

use of lucee.commons.io.cache.CacheEntry in project Lucee by lucee.

the class CacheSupport method values.

// there was the wrong generic type defined in the older interface, because of that we do not define a generic type at all here, just to be sure
@Override
public List values(CacheKeyFilter filter) throws IOException {
    if (CacheUtil.allowAll(filter))
        return values();
    List<String> keys = keys();
    List<Object> list = new ArrayList<Object>();
    Iterator<String> it = keys.iterator();
    String key;
    while (it.hasNext()) {
        key = it.next();
        if (filter.accept(key)) {
            CacheEntry ce = getQuiet(key, null);
            if (// possible that the entry is gone since keys(); call above
            ce != null)
                list.add(ce.getValue());
        }
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) CacheEntry(lucee.commons.io.cache.CacheEntry)

Aggregations

CacheEntry (lucee.commons.io.cache.CacheEntry)14 ArrayList (java.util.ArrayList)5 Cache (lucee.commons.io.cache.Cache)5 IOException (java.io.IOException)4 StructImpl (lucee.runtime.type.StructImpl)4 Struct (lucee.runtime.type.Struct)3 RamCache (lucee.runtime.cache.ram.RamCache)2 WildCardFilter (lucee.runtime.cache.util.WildCardFilter)2 Date (java.util.Date)1 Iterator (java.util.Iterator)1 List (java.util.List)1 CacheException (lucee.commons.io.cache.exp.CacheException)1 QueryCacheItem (lucee.runtime.cache.tag.query.QueryCacheItem)1 FunctionException (lucee.runtime.exp.FunctionException)1 PageException (lucee.runtime.exp.PageException)1 GetHttpTimeString (lucee.runtime.functions.dateTime.GetHttpTimeString)1 StorageScopeCache (lucee.runtime.type.scope.storage.StorageScopeCache)1