Search in sources :

Example 1 with IKStorageScopeClient

use of lucee.runtime.type.scope.client.IKStorageScopeClient in project Lucee by lucee.

the class IKStorageScopeSupport method getInstance.

public static Scope getInstance(int scope, IKHandler handler, String appName, String name, PageContext pc, Scope existing, Log log) throws PageException {
    IKStorageValue sv = null;
    if (Scope.SCOPE_SESSION == scope)
        sv = handler.loadData(pc, appName, name, "session", Scope.SCOPE_SESSION, log);
    else if (Scope.SCOPE_CLIENT == scope)
        sv = handler.loadData(pc, appName, name, "client", Scope.SCOPE_CLIENT, log);
    if (sv != null) {
        long time = sv.lastModified();
        if (existing instanceof IKStorageScopeSupport) {
            IKStorageScopeSupport tmp = ((IKStorageScopeSupport) existing);
            if (tmp.lastModified() >= time && name.equalsIgnoreCase(tmp.getStorage())) {
                return existing;
            }
        }
        if (Scope.SCOPE_SESSION == scope)
            return new IKStorageScopeSession(pc, handler, appName, name, sv.getValue(), time);
        else if (Scope.SCOPE_CLIENT == scope)
            return new IKStorageScopeClient(pc, handler, appName, name, sv.getValue(), time);
    } else if (existing instanceof IKStorageScopeSupport) {
        IKStorageScopeSupport tmp = ((IKStorageScopeSupport) existing);
        if (name.equalsIgnoreCase(tmp.getStorage())) {
            return existing;
        }
    }
    IKStorageScopeSupport rtn = null;
    ConcurrentHashMapPro<Key, IKStorageScopeItem> map = new ConcurrentHashMapPro<Collection.Key, IKStorageScopeItem>();
    if (Scope.SCOPE_SESSION == scope)
        rtn = new IKStorageScopeSession(pc, handler, appName, name, map, 0);
    else if (Scope.SCOPE_CLIENT == scope)
        rtn = new IKStorageScopeClient(pc, handler, appName, name, map, 0);
    rtn.store(pc);
    return rtn;
}
Also used : IKStorageScopeSession(lucee.runtime.type.scope.session.IKStorageScopeSession) Collection(lucee.runtime.type.Collection) IKStorageScopeClient(lucee.runtime.type.scope.client.IKStorageScopeClient) ConcurrentHashMapPro(lucee.commons.collection.concurrent.ConcurrentHashMapPro)

Aggregations

ConcurrentHashMapPro (lucee.commons.collection.concurrent.ConcurrentHashMapPro)1 Collection (lucee.runtime.type.Collection)1 IKStorageScopeClient (lucee.runtime.type.scope.client.IKStorageScopeClient)1 IKStorageScopeSession (lucee.runtime.type.scope.session.IKStorageScopeSession)1