Search in sources :

Example 41 with ConfigImpl

use of lucee.runtime.config.ConfigImpl 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 42 with ConfigImpl

use of lucee.runtime.config.ConfigImpl 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 43 with ConfigImpl

use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.

the class CacheSetProperties method getCaches.

private static CacheConnection[] getCaches(PageContext pc, String cacheName) throws CacheException {
    ConfigImpl config = (ConfigImpl) pc.getConfig();
    if (StringUtil.isEmpty(cacheName)) {
        return new CacheConnection[] { config.getCacheDefaultConnection(Config.CACHE_TYPE_OBJECT), config.getCacheDefaultConnection(Config.CACHE_TYPE_TEMPLATE) };
    // MUST which one is first
    }
    ArrayList<CacheConnection> list = new ArrayList<CacheConnection>();
    String name;
    String[] names = ListUtil.listToStringArray(cacheName, ',');
    for (int i = 0; i < names.length; i++) {
        name = names[i].trim().toLowerCase();
        if (name.equalsIgnoreCase("template"))
            list.add(config.getCacheDefaultConnection(Config.CACHE_TYPE_TEMPLATE));
        else if (name.equalsIgnoreCase("object"))
            list.add(config.getCacheDefaultConnection(Config.CACHE_TYPE_OBJECT));
        else {
            CacheConnection cc = config.getCacheConnections().get(name);
            if (cc == null)
                throw new CacheException("there is no cache defined with name [" + name + "]");
            list.add(cc);
        }
    }
    return list.toArray(new CacheConnection[list.size()]);
}
Also used : CacheException(lucee.commons.io.cache.exp.CacheException) ArrayList(java.util.ArrayList) CacheConnection(lucee.runtime.cache.CacheConnection) ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 44 with ConfigImpl

use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.

the class ComponentCacheClear method call.

public static String call(PageContext pc) {
    ConfigImpl config = (ConfigImpl) pc.getConfig();
    config.clearComponentCache();
    return null;
}
Also used : ConfigImpl(lucee.runtime.config.ConfigImpl)

Example 45 with ConfigImpl

use of lucee.runtime.config.ConfigImpl in project Lucee by lucee.

the class CTCacheClear method call.

public static String call(PageContext pc) {
    ConfigImpl config = (ConfigImpl) pc.getConfig();
    config.clearCTCache();
    return null;
}
Also used : ConfigImpl(lucee.runtime.config.ConfigImpl)

Aggregations

ConfigImpl (lucee.runtime.config.ConfigImpl)47 PageException (lucee.runtime.exp.PageException)15 Log (lucee.commons.io.log.Log)14 DatasourceConnection (lucee.runtime.db.DatasourceConnection)10 ApplicationException (lucee.runtime.exp.ApplicationException)8 Struct (lucee.runtime.type.Struct)8 StructImpl (lucee.runtime.type.StructImpl)8 DataSource (lucee.runtime.db.DataSource)7 DatasourceConnectionPool (lucee.runtime.db.DatasourceConnectionPool)7 SQLExecutor (lucee.runtime.type.scope.storage.db.SQLExecutor)7 SQLException (java.sql.SQLException)6 Resource (lucee.commons.io.res.Resource)6 PageContextImpl (lucee.runtime.PageContextImpl)6 PageSource (lucee.runtime.PageSource)6 QueryImpl (lucee.runtime.type.QueryImpl)5 ArrayList (java.util.ArrayList)4 ConfigWebImpl (lucee.runtime.config.ConfigWebImpl)4 DatabaseException (lucee.runtime.exp.DatabaseException)4 Key (lucee.runtime.type.Collection.Key)4 IOException (java.io.IOException)3