use of lucee.commons.io.cache.Cache in project Lucee by lucee.
the class IKHandlerCache method unstore.
@Override
public void unstore(IKStorageScopeSupport storageScope, PageContext pc, String appName, String name, String cfid, Log log) {
try {
Cache cache = getCache(pc, name);
String key = getKey(cfid, appName, storageScope.getTypeAsString());
synchronized (cache) {
cache.remove(key);
}
} catch (Exception pe) {
}
}
use of lucee.commons.io.cache.Cache in project Lucee by lucee.
the class CacheStorageScopeCleaner method clean.
private void clean(CacheConnection cc, ConfigWebImpl config) throws IOException {
Cache cache = cc.getInstance(config);
int len = filter.length(), index;
List<CacheEntry> entries = cache.entries(filter);
CacheEntry ce;
long expires;
String key, appname, cfid;
if (entries.size() > 0) {
Iterator<CacheEntry> it = entries.iterator();
while (it.hasNext()) {
ce = it.next();
Date lm = ce.lastModified();
long time = lm != null ? lm.getTime() : 0;
expires = time + ce.idleTimeSpan() - StorageScopeCache.SAVE_EXPIRES_OFFSET;
if (expires <= System.currentTimeMillis()) {
key = ce.getKey().substring(len);
index = key.indexOf(':');
cfid = key.substring(0, index);
appname = key.substring(index + 1);
if (listener != null)
listener.doEnd(engine, this, appname, cfid);
info("remove " + strType + "/" + appname + "/" + cfid + " from cache " + cc.getName());
engine.remove(type, appname, cfid);
cache.remove(ce.getKey());
}
}
}
// engine.remove(type,appName,cfid);
// return (Struct) cache.getValue(key,null);
}
use of lucee.commons.io.cache.Cache in project Lucee by lucee.
the class CacheGetAll method call.
public static Struct call(PageContext pc, String filter, String cacheName) throws PageException {
try {
Cache cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
List<CacheEntry> entries = CacheGetAllIds.isFilter(filter) ? cache.entries(new WildCardFilter(filter, true)) : cache.entries();
Iterator<CacheEntry> it = entries.iterator();
Struct sct = new StructImpl();
CacheEntry entry;
while (it.hasNext()) {
entry = it.next();
sct.setEL(KeyImpl.getInstance(entry.getKey()), entry.getValue());
}
return sct;
} catch (Exception e) {
throw Caster.toPageException(e);
}
}
use of lucee.commons.io.cache.Cache in project Lucee by lucee.
the class CacheRemove method call.
public static String call(PageContext pc, Object ids, boolean throwOnError, String cacheName) throws PageException {
//
Array arr = toArray(ids);
Iterator it = arr.valueIterator();
String id;
Cache cache;
try {
cache = CacheUtil.getCache(pc, cacheName, Config.CACHE_TYPE_OBJECT);
} catch (IOException e) {
throw Caster.toPageException(e);
}
StringBuilder sb = null;
try {
while (it.hasNext()) {
id = CacheUtil.key(Caster.toString(it.next()));
if (!cache.remove(id) && throwOnError) {
if (sb == null)
sb = new StringBuilder();
else
sb.append(',');
sb.append(id);
}
}
} catch (IOException e) {
}
if (throwOnError && sb != null)
throw new ApplicationException("can not remove the elements with the following id(s) [" + sb + "]");
return null;
}
use of lucee.commons.io.cache.Cache in project Lucee by lucee.
the class XMLConfigAdmin method updateCacheConnection.
public void updateCacheConnection(String name, ClassDefinition cd, int _default, Struct custom, boolean readOnly, boolean storage) throws PageException {
checkWriteAccess();
boolean hasAccess = ConfigWebUtil.hasAccess(config, SecurityManagerImpl.TYPE_CACHE);
if (!hasAccess)
throw new SecurityException("no access to update cache connection");
// check parameters
name = name.trim();
if (StringUtil.isEmpty(name))
throw new ExpressionException("name can't be a empty value");
try {
Class clazz;
if (cd.getClassName() != null && cd.getClassName().endsWith(".EHCacheLite"))
clazz = ClassUtil.loadClass(config.getClassLoader(), "org.lucee.extension.cache.eh.EHCache");
else
clazz = ClassUtil.loadClass(config.getClassLoader(), cd.getClassName());
if (!Reflector.isInstaneOf(clazz, Cache.class))
throw new ExpressionException("class [" + clazz.getName() + "] is not of type [" + Cache.class.getName() + "]");
} catch (ClassException e) {
throw new ExpressionException(e.getMessage());
}
Element parent = _getRootElement("cache");
if (name.equalsIgnoreCase(parent.getAttribute("default-template")))
parent.removeAttribute("default-template");
if (name.equalsIgnoreCase(parent.getAttribute("default-object")))
parent.removeAttribute("default-object");
if (name.equalsIgnoreCase(parent.getAttribute("default-query")))
parent.removeAttribute("default-query");
if (name.equalsIgnoreCase(parent.getAttribute("default-resource")))
parent.removeAttribute("default-resource");
if (name.equalsIgnoreCase(parent.getAttribute("default-function")))
parent.removeAttribute("default-function");
if (name.equalsIgnoreCase(parent.getAttribute("default-include")))
parent.removeAttribute("default-include");
if (_default == ConfigImpl.CACHE_TYPE_OBJECT) {
parent.setAttribute("default-object", name);
} else if (_default == ConfigImpl.CACHE_TYPE_TEMPLATE) {
parent.setAttribute("default-template", name);
} else if (_default == ConfigImpl.CACHE_TYPE_QUERY) {
parent.setAttribute("default-query", name);
} else if (_default == ConfigImpl.CACHE_TYPE_RESOURCE) {
parent.setAttribute("default-resource", name);
} else if (_default == ConfigImpl.CACHE_TYPE_FUNCTION) {
parent.setAttribute("default-function", name);
} else if (_default == ConfigImpl.CACHE_TYPE_INCLUDE) {
parent.setAttribute("default-include", name);
} else if (_default == ConfigImpl.CACHE_TYPE_HTTP) {
parent.setAttribute("default-http", name);
} else if (_default == ConfigImpl.CACHE_TYPE_FILE) {
parent.setAttribute("default-file", name);
} else if (_default == ConfigImpl.CACHE_TYPE_WEBSERVICE) {
parent.setAttribute("default-webservice", name);
}
// Update
// boolean isUpdate=false;
Element[] children = XMLConfigWebFactory.getChildren(parent, "connection");
for (int i = 0; i < children.length; i++) {
String n = children[i].getAttribute("name");
Element el = children[i];
if (n.equalsIgnoreCase(name)) {
setClass(el, null, "", cd);
el.setAttribute("custom", toStringURLStyle(custom));
el.setAttribute("read-only", Caster.toString(readOnly));
el.setAttribute("storage", Caster.toString(storage));
return;
}
}
// Insert
Element el = doc.createElement("connection");
parent.appendChild(el);
el.setAttribute("name", name);
setClass(el, null, "", cd);
el.setAttribute("custom", toStringURLStyle(custom));
el.setAttribute("read-only", Caster.toString(readOnly));
el.setAttribute("storage", Caster.toString(storage));
}
Aggregations