Search in sources :

Example 21 with Cache

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

the class CacheUtil method getDefault.

/**
 * get the default cache for a certain type, also check definitions in application context (application . cfc/cfapplication)
 * @param pc current PageContext
 * @param type default type -> Config.CACHE_DEFAULT_...
 * @return matching cache
 * @throws IOException
 */
public static Cache getDefault(PageContext pc, int type) throws IOException {
    // get default from application conetxt
    String name = pc != null ? pc.getApplicationContext().getDefaultCacheName(type) : null;
    if (!StringUtil.isEmpty(name)) {
        Cache cc = getCache(pc, name, null);
        if (cc != null)
            return cc;
    }
    // get default from config
    Config config = ThreadLocalPageContext.getConfig(pc);
    CacheConnection cc = ((ConfigImpl) config).getCacheDefaultConnection(type);
    if (cc == null)
        throw new CacheException("there is no default " + toStringType(type, "") + " cache defined, you need to define this default cache in the Lucee Administrator");
    return cc.getInstance(config);
}
Also used : CacheException(lucee.commons.io.cache.exp.CacheException) Config(lucee.runtime.config.Config) ConfigImpl(lucee.runtime.config.ConfigImpl) Cache(lucee.commons.io.cache.Cache)

Example 22 with Cache

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

the class CacheUtil method getDefault.

/**
 * get the default cache for a certain type, also check definitions in application context (application . cfc/cfapplication)
 * @param pc current PageContext
 * @param type default type -> Config.CACHE_DEFAULT_...
 * @param defaultValue value returned when there is no default cache for this type
 * @return matching cache
 */
public static Cache getDefault(PageContext pc, int type, Cache defaultValue) {
    // get default from application conetx
    String name = null;
    if (pc != null && pc.getApplicationContext() != null)
        name = pc.getApplicationContext().getDefaultCacheName(type);
    Config config = ThreadLocalPageContext.getConfig(pc);
    if (!StringUtil.isEmpty(name)) {
        Cache cc = getCache(pc, name, null);
        if (cc != null)
            return cc;
    }
    // get default from config
    CacheConnection cc = ((ConfigImpl) config).getCacheDefaultConnection(type);
    if (cc == null)
        return defaultValue;
    try {
        return cc.getInstance(config);
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
        return defaultValue;
    }
}
Also used : Config(lucee.runtime.config.Config) ConfigImpl(lucee.runtime.config.ConfigImpl) Cache(lucee.commons.io.cache.Cache)

Example 23 with Cache

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

the class TimespanCacheHandler method getCache.

private Cache getCache(PageContext pc) {
    Cache cache = CacheUtil.getDefault(pc, cacheType, null);
    if (cache == null) {
        if (defaultCache == null) {
            RamCache rm = new RamCache().init(0, 0, RamCache.DEFAULT_CONTROL_INTERVAL);
            rm.decouple();
            defaultCache = rm;
        }
        return defaultCache;
    }
    if (cache instanceof CachePro)
        return ((CachePro) cache).decouple();
    return cache;
}
Also used : CachePro(lucee.commons.io.cache.CachePro) RamCache(lucee.runtime.cache.ram.RamCache) Cache(lucee.commons.io.cache.Cache) RamCache(lucee.runtime.cache.ram.RamCache)

Example 24 with Cache

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

the class CacheResourceProvider method touch.

void touch(String path, String name) throws IOException {
    Cache cache = getCache();
    CacheEntry ce = cache.getCacheEntry(toKey(path, name), null);
    if (ce != null) {
        cache.put(ce.getKey(), ce.getValue(), ce.idleTimeSpan(), ce.liveTimeSpan());
    }
}
Also used : CacheEntry(lucee.commons.io.cache.CacheEntry) 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