public override void SetAndReleaseItemExclusive(HttpContext context, string id, SessionStateStoreData item, object lockId, bool newItem) { // 1 remote call #region Access Log #if TRACE { Handler.LogHandler.Tracking("Access Method: " + this.GetType().ToString() + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;"); } #endif #endregion Access Log // creating a new StoreDataInfo will initialize LockDate to null (unlocked) SessionStoreDataContext data = new SessionStoreDataContext(item); Cache.Add(GetCacheKey(id), (object)SessionStoreDataContext.Serialize(data), DateTime.Now.AddMinutes(item.Timeout)); }
public override void CreateUninitializedItem(HttpContext context, string id, int timeout) { // 1 remote call #region Access Log #if TRACE { Handler.LogHandler.Tracking("Access Method: " + this.GetType().ToString() + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;"); } #endif #endregion Access Log _timeout = timeout; SessionStoreDataContext data = new SessionStoreDataContext(CreateNewStoreData(context, timeout)); Cache.Add(GetCacheKey(id), (object)SessionStoreDataContext.Serialize(data), DateTime.Now.AddMinutes(data.Data.Timeout)); }
public override void ReleaseItemExclusive(HttpContext context, string id, object lockId) { // 1-2 remote calls #region Access Log #if TRACE { Handler.LogHandler.Tracking("Access Method: " + this.GetType().ToString() + "->" + ((object)MethodBase.GetCurrentMethod()).ToString() + " ;"); } #endif #endregion Access Log //todo: replace with single unlock call when available byte[] bytes = Cache.Get <byte[]>(GetCacheKey(id)); if (bytes != null) { SessionStoreDataContext data = SessionStoreDataContext.Deserialize(bytes, context); data.ClearLock(); Cache.Add(GetCacheKey(id), (object)SessionStoreDataContext.Serialize(data), DateTime.Now.AddMinutes(data.Data.Timeout)); } }
private SessionStateStoreData FetchCachedStoreData(HttpContext context, string id, out bool locked, out TimeSpan lockAge, out object lockId, out SessionStateActions actions, bool exclusive) { // 1-2 remote calls locked = false; lockAge = TimeSpan.Zero; lockId = null; actions = SessionStateActions.None; // check for existing session byte[] bytes = Cache.Get <byte[]>(GetCacheKey(id)); if (bytes == null) { return(null); } SessionStoreDataContext data = SessionStoreDataContext.Deserialize(bytes, context); locked = data.IsLocked; if (locked) { lockAge = DateTime.Now.Subtract(data.LockDate.Value); lockId = data.LockDate; // specs require null to be returned return(null); } //todo: rewrite with real locking when available // as of a few microseconds ago, this session was unlocked, so proceed if (exclusive) { data.LockDate = DateTime.Now; // not perfectly thread safe as there can be race conditions between // clustered servers, but this is the best we've got Cache.Add(GetCacheKey(id), (object)SessionStoreDataContext.Serialize(data), DateTime.Now.AddMinutes(data.Data.Timeout)); } return(data.Data); }