use of lucee.runtime.type.scope.storage.IKHandlerCache in project Lucee by lucee.
the class ScopeContext method getClientScope.
public Client getClientScope(PageContext pc) throws PageException {
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfClientContexts, appContext.getName());
// get Client
boolean isMemory = false;
String storage = appContext.getClientstorage();
if (StringUtil.isEmpty(storage, true)) {
storage = ConfigImpl.DEFAULT_STORAGE_CLIENT;
} else if ("ram".equalsIgnoreCase(storage)) {
storage = "memory";
isMemory = true;
} else if ("registry".equalsIgnoreCase(storage)) {
storage = "file";
} else {
storage = storage.toLowerCase();
if ("memory".equals(storage))
isMemory = true;
}
Client existing = (Client) context.get(pc.getCFID());
Client client = appContext.getClientCluster() ? null : existing;
// client=doMemory?(Client) context.get(pc.getCFID()):null;
if (client == null || client.isExpired() || !client.getStorage().equalsIgnoreCase(storage)) {
if ("file".equals(storage)) {
client = ClientFile.getInstance(appContext.getName(), pc, getLog());
} else if ("cookie".equals(storage))
client = ClientCookie.getInstance(appContext.getName(), pc, getLog());
else if ("memory".equals(storage)) {
if (existing != null)
client = existing;
client = ClientMemory.getInstance(pc, getLog());
} else {
DataSource ds = pc.getDataSource(storage, null);
if (ds != null) {
if (INVIDUAL_STORAGE_KEYS) {
try {
client = (Client) IKStorageScopeSupport.getInstance(Scope.SCOPE_CLIENT, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing, getLog());
} catch (PageException pe) {
// code above could fail when an old scope is loaded, remember client scope can be easy be
// 180 days old
client = ClientDatasource.getInstance(storage, pc, getLog());
}
} else
client = ClientDatasource.getInstance(storage, pc, getLog());
} else {
if (INVIDUAL_STORAGE_KEYS) {
try {
client = (Client) IKStorageScopeSupport.getInstance(Scope.SCOPE_CLIENT, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
} catch (PageException pe) {
// code above could fail when an old scope is loaded, remember client scope can be easy be
// 180 days old
client = ClientCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
}
} else
client = ClientCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
}
if (client == null) {
// datasource not enabled for storage
if (ds != null)
throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session/client storage, you have to enable it in the Lucee administrator.");
CacheConnection cc = CacheUtil.getCacheConnection(pc, storage, null);
if (cc != null)
throw new ApplicationException("cache [" + storage + "] is not enabled to be used as a session/client storage, you have to enable it in the Lucee administrator.");
throw new ApplicationException("there is no cache or datasource with name [" + storage + "] defined.");
}
}
client.setStorage(storage);
context.put(pc.getCFID(), client);
} else
getLog().log(Log.LEVEL_INFO, "scope-context", "use existing client scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
client.touchBeforeRequest(pc);
return client;
}
use of lucee.runtime.type.scope.storage.IKHandlerCache in project Lucee by lucee.
the class ScopeContext method hasExistingCFSessionScope.
private boolean hasExistingCFSessionScope(PageContext pc) {
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
// get Session
String storage = appContext.getSessionstorage();
if (StringUtil.isEmpty(storage, true))
storage = "memory";
else if ("ram".equalsIgnoreCase(storage))
storage = "memory";
else if ("registry".equalsIgnoreCase(storage))
storage = "file";
else
storage = storage.toLowerCase();
Session session = (Session) context.get(pc.getCFID());
if (!(session instanceof StorageScope) || session.isExpired() || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
if ("memory".equals(storage))
return false;
else if ("file".equals(storage))
return SessionFile.hasInstance(appContext.getName(), pc);
else if ("cookie".equals(storage))
return SessionCookie.hasInstance(appContext.getName(), pc);
else {
DataSource ds = pc.getConfig().getDataSource(storage, null);
if (ds != null && ds.isStorage()) {
if (INVIDUAL_STORAGE_KEYS) {
return IKStorageScopeSupport.hasInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc);
} else {
if (SessionDatasource.hasInstance(storage, pc))
return true;
}
}
if (INVIDUAL_STORAGE_KEYS)
return IKStorageScopeSupport.hasInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc);
return SessionCache.hasInstance(storage, appContext.getName(), pc);
}
}
return true;
}
use of lucee.runtime.type.scope.storage.IKHandlerCache in project Lucee by lucee.
the class ScopeContext method getCFSessionScope.
/**
* return cf session scope
*
* @param pc PageContext
* @param isNew
* @return cf session matching the context
* @throws PageException
*/
private Session getCFSessionScope(PageContext pc, RefBoolean isNew) throws PageException {
ApplicationContext appContext = pc.getApplicationContext();
// get Context
Map<String, Scope> context = getSubMap(cfSessionContexts, appContext.getName());
// get Session
boolean isMemory = false;
String storage = appContext.getSessionstorage();
if (StringUtil.isEmpty(storage, true)) {
storage = ConfigImpl.DEFAULT_STORAGE_SESSION;
isMemory = true;
} else if ("ram".equalsIgnoreCase(storage)) {
storage = "memory";
isMemory = true;
} else if ("registry".equalsIgnoreCase(storage)) {
storage = "file";
} else {
storage = storage.toLowerCase();
if ("memory".equals(storage))
isMemory = true;
}
Session existing = (Session) context.get(pc.getCFID());
if (existing != null && (existing.isExpired() || !(existing instanceof StorageScope)))
// second should not happen
existing = null;
Session session = appContext.getSessionCluster() ? null : existing;
if (session == null || !(session instanceof StorageScope) || !((StorageScope) session).getStorage().equalsIgnoreCase(storage)) {
// not necessary to check session in the same way, because it is overwritten anyway
if (isMemory) {
if (existing != null)
session = existing;
else
session = SessionMemory.getInstance(pc, isNew, getLog());
} else if ("file".equals(storage)) {
session = SessionFile.getInstance(appContext.getName(), pc, getLog());
} else if ("cookie".equals(storage))
session = SessionCookie.getInstance(appContext.getName(), pc, getLog());
else {
DataSource ds = pc.getDataSource(storage, null);
if (ds != null && ds.isStorage()) {
if (INVIDUAL_STORAGE_KEYS) {
try {
session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerDatasource(), appContext.getName(), storage, pc, existing, getLog());
} catch (PageException pe) {
session = SessionDatasource.getInstance(storage, pc, getLog(), null);
}
} else
session = SessionDatasource.getInstance(storage, pc, getLog(), null);
} else {
if (INVIDUAL_STORAGE_KEYS) {
try {
session = (Session) IKStorageScopeSupport.getInstance(Scope.SCOPE_SESSION, new IKHandlerCache(), appContext.getName(), storage, pc, existing, getLog());
} catch (PageException pe) {
session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
}
} else
session = SessionCache.getInstance(storage, appContext.getName(), pc, existing, getLog(), null);
}
if (session == null) {
// datasource not enabled for storage
if (ds != null)
throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session/client storage, " + "you have to enable it in the Lucee administrator or define key \"storage=true\" for datasources defined in the application event handler.");
CacheConnection cc = CacheUtil.getCacheConnection(pc, storage, null);
if (cc != null)
throw new ApplicationException("cache [" + storage + "] is not enabled to be used as a session/client storage, you have to enable it in the Lucee administrator.");
throw new ApplicationException("there is no cache or datasource with name [" + storage + "] defined.");
}
}
if (session instanceof StorageScope)
((StorageScope) session).setStorage(storage);
context.put(pc.getCFID(), session);
isNew.setValue(true);
} else {
getLog().log(Log.LEVEL_INFO, "scope-context", "use existing session scope for " + appContext.getName() + "/" + pc.getCFID() + " from storage " + storage);
}
session.touchBeforeRequest(pc);
return session;
}
Aggregations