Ejemplo n.º 1
0
        protected override object CreateEmptySession(IAspEnvironmentContext context, int sessionTimeout)
        {
            var session = new NCacheSessionData();

            session.Items.Add(NCacheStatics.EmptySessionFlag, null);
            return(session);
        }
Ejemplo n.º 2
0
 public async Task CommitAsync(CancellationToken cancellationToken = default(CancellationToken))
 {
     if (!_readonly)
     {
         if (IsAvailable)
         {
             if (EmptySession)
             {
                 if (_isDirty)
                 {
                     SessionInitializationActions actions;
                     _data = _cacheStorage.GetItemExclusive(_context, _sessionId, out _locked, out _lockAge, out _lockId,
                                                            out actions) as NCacheSessionData;
                     _cacheStorage.SetAndReleaseItemExclusive(_context, _sessionId, _data, _lockId, _newSession,
                                                              Convert.ToInt32(_sessionTimeout.TotalMinutes));
                     _isDirty = false;
                 }
             }
             else
             {
                 if (_isDirty)
                 {
                     _cacheStorage.SetAndReleaseItemExclusive(_context, _sessionId, _data, _lockId, _newSession,
                                                              Convert.ToInt32(_sessionTimeout.TotalMinutes));
                     _isDirty = false;
                 }
                 else
                 {
                     _cacheStorage.ReleaseItemExclusive(_context, _sessionId, _lockId);
                 }
             }
             IsAvailable = false;
         }
     }
 }
Ejemplo n.º 3
0
 internal NCacheSession(HttpContext context, string sessionId, ISessionStoreService cacheStorage, bool readOnly, bool newSession, int requestTimeout, TimeSpan sessionTimeout)
 {
     _sessionId      = sessionId;
     _context        = context;
     _data           = new NCacheSessionData();
     _cacheStorage   = cacheStorage;
     _readonly       = readOnly;
     _newSession     = newSession;
     _timeoutSpan    = TimeSpan.FromSeconds(requestTimeout);
     _sessionTimeout = sessionTimeout;
 }
Ejemplo n.º 4
0
        public async Task LoadAsync(CancellationToken cancellationToken = default(CancellationToken))
        {
            SessionInitializationActions actions;

            if (_readonly)
            {
                _data =
                    _cacheStorage.GetItem(_context, _sessionId, out _locked, out _lockAge, out _lockId, out actions) as
                    NCacheSessionData;
            }
            else
            {
                _data =
                    _cacheStorage.GetItemExclusive(_context, _sessionId, out _locked, out _lockAge, out _lockId,
                                                   out actions) as NCacheSessionData;
            }
            if (_data == null)
            {
                if (_locked)
                {
                    PollAndRetryGetItemExclusive();
                }
                else
                {
                    _data      = new NCacheSessionData();
                    NewSession = true;
                }
            }

            if (_data != null && _data.Items.ContainsKey(NCacheStatics.EmptySessionFlag))
            {
                EmptySession = NewSession = true;
            }

            IsAvailable = true;
            _isDirty    = false;
        }
Ejemplo n.º 5
0
        private void PollAndRetryGetItemExclusive()
        {
            SessionInitializationActions actions;

            if (!_readonly)
            {
                while (_locked && _lockAge < _timeoutSpan)
                {
                    Thread.Sleep(500);
                    _data = _cacheStorage.GetItemExclusive(_context, _sessionId, out _locked, out _lockAge, out _lockId,
                                                           out actions) as NCacheSessionData;
                }
                if (_locked && _lockAge > _timeoutSpan)
                {
                    _cacheStorage.ReleaseItemExclusive(_context, _sessionId, _lockId);
                    _data = _cacheStorage.GetItemExclusive(_context, _sessionId, out _locked, out _lockAge, out _lockId,
                                                           out actions) as NCacheSessionData;
                    if (_locked)
                    {
                        PollAndRetryGetItemExclusive();
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected override byte[] SerializeSession(object sessionData)
        {
            NCacheSessionData session = sessionData as NCacheSessionData;

            return(SessionSerializer.Serialize(session));
        }