Search in sources :

Example 6 with Cache

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

the class CacheUtil method remove.

public static void remove(ConfigWeb config, CacheConnection cc) throws Throwable {
    Cache c = cc.getInstance(config);
    // FUTURE no reflection needed
    Method remove = null;
    try {
        remove = c.getClass().getMethod("remove", new Class[0]);
    } catch (Exception ioe) {
        c.remove((CacheEntryFilter) null);
        return;
    }
    try {
        remove.invoke(c, new Object[0]);
    } catch (InvocationTargetException e) {
        throw e.getTargetException();
    }
}
Also used : CacheEntryFilter(lucee.commons.io.cache.CacheEntryFilter) Method(java.lang.reflect.Method) IOException(java.io.IOException) CacheException(lucee.commons.io.cache.exp.CacheException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Cache(lucee.commons.io.cache.Cache)

Example 7 with Cache

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

the class CacheUtil method release.

public static void release(CacheConnection cc) throws IOException {
    Cache c = ((CacheConnectionPlus) cc).getLoadedInstance();
    if (c == null)
        return;
    // FUTURE no reflection needed
    Method release = null;
    try {
        release = c.getClass().getMethod("release", new Class[] {});
    } catch (Exception e) {
        return;
    }
    try {
        if (release != null)
            release.invoke(c, new Object[] {});
    } catch (Exception e) {
        throw ExceptionUtil.toIOException(e);
    }
}
Also used : Method(java.lang.reflect.Method) IOException(java.io.IOException) CacheException(lucee.commons.io.cache.exp.CacheException) InvocationTargetException(java.lang.reflect.InvocationTargetException) Cache(lucee.commons.io.cache.Cache)

Example 8 with Cache

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

the class CacheItem method getInstance.

public static CacheItem getInstance(PageContext pc, String id, String key, boolean useId, Resource dir, String cacheName, TimeSpan timespan) throws IOException {
    HttpServletRequest req = pc.getHttpServletRequest();
    Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_TEMPLATE, null);
    if (cache != null)
        return new CacheItemCache(pc, req, id, key, useId, cache, timespan);
    return new CacheItemFS(pc, req, id, key, useId, dir);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Cache(lucee.commons.io.cache.Cache)

Example 9 with Cache

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

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

the class IKHandlerCache method loadData.

@Override
public IKStorageValue loadData(PageContext pc, String appName, String name, String strType, int type, Log log) throws PageException {
    Cache cache = getCache(pc, name);
    String key = getKey(pc.getCFID(), appName, strType);
    synchronized (cache) {
        // sync necessary?
        Object val = cache.getValue(key, null);
        if (val instanceof byte[][]) {
            ScopeContext.info(log, "load existing data from  cache [" + name + "] to create " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
            return new IKStorageValue((byte[][]) val);
        } else if (val instanceof IKStorageValue) {
            ScopeContext.info(log, "load existing data from  cache [" + name + "] to create " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
            return (IKStorageValue) val;
        } else {
            ScopeContext.info(log, "create new " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID() + " in cache [" + name + "]");
        }
        return null;
    }
}
Also used : Cache(lucee.commons.io.cache.Cache) RamCache(lucee.runtime.cache.ram.RamCache)

Aggregations

Cache (lucee.commons.io.cache.Cache)24 IOException (java.io.IOException)10 PageException (lucee.runtime.exp.PageException)8 RamCache (lucee.runtime.cache.ram.RamCache)7 ApplicationException (lucee.runtime.exp.ApplicationException)6 CacheEntry (lucee.commons.io.cache.CacheEntry)5 FunctionException (lucee.runtime.exp.FunctionException)4 Struct (lucee.runtime.type.Struct)4 CacheException (lucee.commons.io.cache.exp.CacheException)3 WildCardFilter (lucee.runtime.cache.util.WildCardFilter)3 Array (lucee.runtime.type.Array)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 Config (lucee.runtime.config.Config)2 ConfigImpl (lucee.runtime.config.ConfigImpl)2 StructImpl (lucee.runtime.type.StructImpl)2 Date (java.util.Date)1 Iterator (java.util.Iterator)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 CacheEntryFilter (lucee.commons.io.cache.CacheEntryFilter)1