Search in sources :

Example 1 with CacheEntry

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

the class Cache method doGet.

private void doGet() throws PageException, IOException {
    required("cache", "id", id);
    required("cache", "name", name);
    String id = Caster.toString(this.id);
    if (metadata == null) {
        pageContext.setVariable(name, CacheGet.call(pageContext, id, throwOnError, cachename));
    } else {
        lucee.commons.io.cache.Cache cache = CacheUtil.getCache(pageContext, cachename, Config.CACHE_TYPE_OBJECT);
        CacheEntry entry = throwOnError ? cache.getCacheEntry(CacheUtil.key(id)) : cache.getCacheEntry(CacheUtil.key(id), null);
        if (entry != null) {
            pageContext.setVariable(name, entry.getValue());
            pageContext.setVariable(metadata, entry.getCustomInfo());
        } else {
            pageContext.setVariable(metadata, new StructImpl());
        }
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) GetHttpTimeString(lucee.runtime.functions.dateTime.GetHttpTimeString) CacheEntry(lucee.commons.io.cache.CacheEntry)

Example 2 with CacheEntry

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

the class CacheGetMetadata method call.

public static Struct call(PageContext pc, String id, String cacheName) throws PageException {
    try {
        Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
        CacheEntry entry = cache.getCacheEntry(CacheUtil.key(id));
        Struct info = new StructImpl();
        info.set(CACHE_HITCOUNT, new Double(cache.hitCount()));
        info.set(CACHE_MISSCOUNT, new Double(cache.missCount()));
        info.set(CACHE_CUSTOM, cache.getCustomInfo());
        info.set(KeyConstants._custom, entry.getCustomInfo());
        info.set(CREATED_TIME, entry.created());
        info.set(KeyConstants._hitcount, new Double(entry.hitCount()));
        info.set(IDLE_TIME, new Double(entry.idleTimeSpan()));
        info.set(LAST_HIT, entry.lastHit());
        info.set(LAST_UPDATED, entry.lastModified());
        info.set(KeyConstants._size, new Double(entry.size()));
        info.set(KeyConstants._timespan, new Double(entry.liveTimeSpan()));
        return info;
    } catch (IOException e) {
        throw Caster.toPageException(e);
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) IOException(java.io.IOException) CacheEntry(lucee.commons.io.cache.CacheEntry) Cache(lucee.commons.io.cache.Cache) Struct(lucee.runtime.type.Struct)

Example 3 with CacheEntry

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

the class CacheSupport method keys.

@Override
public List<String> keys(CacheEntryFilter filter) throws IOException {
    boolean all = CacheUtil.allowAll(filter);
    List<String> keys = keys();
    List<String> list = new ArrayList<String>();
    Iterator<String> it = keys.iterator();
    String key;
    CacheEntry entry;
    while (it.hasNext()) {
        key = it.next();
        entry = getQuiet(key, null);
        if (all || filter.accept(entry))
            list.add(key);
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) CacheEntry(lucee.commons.io.cache.CacheEntry)

Example 4 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(CacheEntryFilter 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;
    CacheEntry entry;
    while (it.hasNext()) {
        key = it.next();
        entry = getQuiet(key, null);
        if (filter.accept(entry))
            list.add(entry.getValue());
    }
    return list;
}
Also used : ArrayList(java.util.ArrayList) CacheEntry(lucee.commons.io.cache.CacheEntry)

Example 5 with CacheEntry

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

the class CacheSupport method entries.

@Override
public List<CacheEntry> entries(CacheEntryFilter filter) throws IOException {
    List<String> keys = keys();
    List<CacheEntry> list = new ArrayList<CacheEntry>();
    Iterator<String> it = keys.iterator();
    CacheEntry entry;
    while (it.hasNext()) {
        entry = getQuiet(it.next(), null);
        if (filter.accept(entry))
            list.add(entry);
    }
    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