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;
}
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);
}
}
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) {
}
}
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;
}
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);
}
}
Aggregations