Search in sources :

Example 11 with Cache

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

the class StorageScopeCache method _loadData.

protected static StorageValue _loadData(PageContext pc, String cacheName, String appName, String strType, Log log) throws PageException {
    Cache cache = getCache(pc, cacheName);
    String key = getKey(pc.getCFID(), appName, strType);
    Object val = cache.getValue(key, null);
    if (val instanceof StorageValue) {
        ScopeContext.info(log, "load existing data from  cache [" + cacheName + "] to create " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID());
        return (StorageValue) val;
    } else {
        ScopeContext.info(log, "create new " + strType + " scope for " + pc.getApplicationContext().getName() + "/" + pc.getCFID() + " in cache [" + cacheName + "]");
    }
    return null;
}
Also used : Cache(lucee.commons.io.cache.Cache)

Example 12 with Cache

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

the class StorageScopeCache method store.

@Override
public void store(PageContext pc) {
    try {
        Cache cache = getCache(ThreadLocalPageContext.get(pc), cacheName);
        String key = getKey(cfid, appName, getTypeAsString());
        synchronized (cache) {
            Object existingVal = cache.getValue(key, null);
            if (existingVal instanceof StorageValue && ((StorageValue) existingVal).lastModified() > lastModified()) {
                Struct trg = ((Struct) ((StorageValue) existingVal).getValue());
                StructUtil.copy(sct, trg, true);
                sct = trg;
            }
            cache.put(key, new StorageValue(sct), new Long(getTimeSpan()), null);
        }
    } catch (Exception pe) {
        SystemOut.printDate(pe);
    }
}
Also used : IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache) Struct(lucee.runtime.type.Struct)

Example 13 with Cache

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

the class StorageScopeCache method unstore.

@Override
public void unstore(PageContext pc) {
    try {
        Cache cache = getCache(ThreadLocalPageContext.get(pc), cacheName);
        String key = getKey(cfid, appName, getTypeAsString());
        synchronized (cache) {
            cache.remove(key);
        }
    } catch (Exception pe) {
    }
}
Also used : IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache)

Example 14 with Cache

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

the class CacheResourceProvider method getCache.

public Cache getCache() {
    PageContext pc = ThreadLocalPageContext.get();
    Cache c = CacheUtil.getDefault(pc, Config.CACHE_TYPE_RESOURCE, null);
    if (c == null) {
        // CFMLEngineImpl e=null;
        if (defaultCache == null) {
            defaultCache = new RamCache().init(0, 0, RamCache.DEFAULT_CONTROL_INTERVAL);
        }
        c = defaultCache;
    }
    if (!inits.contains(c.hashCode())) {
        String k = toKey("null", "");
        try {
            if (!c.contains(k)) {
                CacheResourceCore value = new CacheResourceCore(CacheResourceCore.TYPE_DIRECTORY, null, "");
                c.put(k, value, Constants.LONG_ZERO, Constants.LONG_ZERO);
            }
        } catch (IOException e) {
        // simply ignore
        }
        inits.add(c.hashCode());
    }
    return c;
}
Also used : PageContext(lucee.runtime.PageContext) ThreadLocalPageContext(lucee.runtime.engine.ThreadLocalPageContext) IOException(java.io.IOException) RamCache(lucee.runtime.cache.ram.RamCache) Cache(lucee.commons.io.cache.Cache) RamCache(lucee.runtime.cache.ram.RamCache)

Example 15 with Cache

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

the class IKHandlerCache method store.

@Override
public void store(IKStorageScopeSupport storageScope, PageContext pc, String appName, String name, String cfid, MapPro<Collection.Key, IKStorageScopeItem> data, Log log) {
    try {
        Cache cache = getCache(ThreadLocalPageContext.get(pc), name);
        String key = getKey(cfid, appName, storageScope.getTypeAsString());
        synchronized (cache) {
            Object existingVal = cache.getValue(key, null);
            // FUTURE add IKStorageValue to loader and then the byte array impl is no longer needed
            cache.put(key, deserializeIKStorageValueSupported(cache) ? new IKStorageValue(IKStorageScopeSupport.prepareToStore(data, existingVal, storageScope.lastModified())) : IKStorageValue.toByteRepresentation(IKStorageScopeSupport.prepareToStore(data, existingVal, storageScope.lastModified())), // new IKStorageValue(IKStorageScopeSupport.prepareToStore(data,existingVal,storageScope.lastModified())),
            new Long(storageScope.getTimeSpan()), null);
        }
    } catch (Exception pe) {
        SystemOut.printDate(pe);
    }
}
Also used : IOException(java.io.IOException) ApplicationException(lucee.runtime.exp.ApplicationException) PageException(lucee.runtime.exp.PageException) 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