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))) existing = null; // second should not happen

	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) {
			if (!ds.isStorage()) throw new ApplicationException("datasource [" + storage + "] is not enabled to be used as session storage, "
				+ "you have to enable it in the Lucee administrator or define key \"storage=true\" for datasources defined in the application event handler.");
			throw new ApplicationException("datasource [" + storage
				+ "] could not be reached for session storage. Please make sure the datasource settings are correct, and the datasource is available.");
		    }
		    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;
    }
private Session getCFSessionScope ( PageContext pc , RefBoolean isNew ) throws PageException { ApplicationContext appContext = pc . getApplicationContext ( ) ; Map < String , Scope > context = getSubMap ( cfSessionContexts , appContext . getName ( ) ) ; 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 ) ) ) existing = null ; Session session = appContext . getSessionCluster ( ) ? null : existing ; if ( session == null || ! ( session instanceof StorageScope ) || ! ( ( StorageScope ) session ) . getStorage ( ) . equalsIgnoreCase ( storage ) ) { 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 ) { if ( ds != null ) { if ( ! ds . isStorage ( ) ) throw new ApplicationException ( "datasource [" + storage + "] is not enabled to be used as session storage, " + "you have to enable it in the Lucee administrator or define key \"storage=true\" for datasources defined in the application event handler." ) ; throw new ApplicationException ( "datasource [" + storage + "] could not be reached for session storage. Please make sure the datasource settings are correct, and the datasource is available." ) ; } 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 ; }
return cf session scope

@param pc PageContext
@param isNew
@return cf session matching the context
@throws PageException