Search in sources :

Example 16 with Cache

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

Example 17 with Cache

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);
}
Also used : CacheEntry(lucee.commons.io.cache.CacheEntry) Date(java.util.Date) StorageScopeCache(lucee.runtime.type.scope.storage.StorageScopeCache) Cache(lucee.commons.io.cache.Cache)

Example 18 with Cache

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);
    }
}
Also used : StructImpl(lucee.runtime.type.StructImpl) CacheEntry(lucee.commons.io.cache.CacheEntry) WildCardFilter(lucee.runtime.cache.util.WildCardFilter) FunctionException(lucee.runtime.exp.FunctionException) PageException(lucee.runtime.exp.PageException) Cache(lucee.commons.io.cache.Cache) Struct(lucee.runtime.type.Struct)

Example 19 with Cache

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;
}
Also used : Array(lucee.runtime.type.Array) ApplicationException(lucee.runtime.exp.ApplicationException) Iterator(java.util.Iterator) IOException(java.io.IOException) Cache(lucee.commons.io.cache.Cache)

Example 20 with Cache

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));
}
Also used : Element(org.w3c.dom.Element) ClassException(lucee.commons.lang.ClassException) SecurityException(lucee.runtime.exp.SecurityException) ExpressionException(lucee.runtime.exp.ExpressionException) Cache(lucee.commons.io.cache.Cache)

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