public static void RemoveSession(String key)
 {
     lock (sessions)
     {
         if (sessions.Contains(key))
         {
             sessions.Remove(key);
         }
         if (HttpRuntime.Cache[key].IsNull())
         {
             return;
         }
         var session = HttpRuntime.Cache.Remove(key) as ScriptSession;
         if (!session.IsNull())
         {
             session.Dispose();
         }
         TurboConsoleLog.Debug($"Script session '{key}' disposed.");
     }
 }
        public static ScriptSession GetSession(String persistentId, String applicationType, Boolean personalizedSettings)
        {
            var autoDispose = String.IsNullOrEmpty(persistentId);

            if (autoDispose)
            {
                persistentId = Guid.NewGuid().ToString();
            }
            var sessionKey = GetSessionKey(persistentId);

            lock (sessions)
            {
                if (SessionExists(persistentId))
                {
                    return(HttpRuntime.Cache[sessionKey] as ScriptSession);
                }

                var session = new ScriptSession(applicationType, personalizedSettings)
                {
                    ID = persistentId
                };

                TurboConsoleLog.Debug($"New script session with key '{sessionKey}' created.");
                if (autoDispose)
                {
                    //this only should be set if new session has been created - do not change!
                    session.AutoDispose = true;
                }
                var expiration = Sitecore.Configuration.Settings.GetIntSetting(expirationSetting, 30);
                HttpRuntime.Cache.Add(sessionKey, session, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, expiration, 0), CacheItemPriority.Normal, CacheItemRemoved);
                sessions.Add(sessionKey);
                session.ID  = persistentId;
                session.Key = sessionKey;
                session.Initialize();
                return(session);
            }
        }