/// <summary> /// Gets a session record from an XSRF token /// </summary> /// <returns>The session record.</returns> /// <param name="xsrf">The XSRF token.</param> public async Task <SessionRecord> GetSessionFromXSRFAsync(string xsrf) { string txt; using (await m_lock.LockAsync()) m_xsrf_storage.TryGetValue(xsrf, out txt); if (string.IsNullOrWhiteSpace(txt)) { return(null); } return(PrimitiveSerializer.Deserialize <SessionRecord>(txt)); }
/// <summary> /// Called periodically to expire old items /// </summary> /// <returns>An awaitable task.</returns> public async Task ExpireOldItemsAsync() { using (await m_lock.LockAsync()) { var to_remove = new List <string>(); foreach (var e in m_cookie_storage) { var ds = PrimitiveSerializer.Deserialize <SessionRecord>(e.Value); if (Utility.IsNullOrExpired(ds)) { to_remove.Add(e.Key); if (!string.IsNullOrWhiteSpace(ds.XSRFToken)) { m_xsrf_storage.Remove(ds.XSRFToken); } } } foreach (var r in to_remove) { m_cookie_storage.Remove(r); } to_remove.Clear(); foreach (var e in m_xsrf_storage) { var ds = PrimitiveSerializer.Deserialize <SessionRecord>(e.Value); if (Utility.IsNullOrExpired(ds)) { to_remove.Add(e.Key); if (!string.IsNullOrWhiteSpace(ds.Cookie)) { m_cookie_storage.Remove(ds.Cookie); } } } foreach (var r in to_remove) { m_xsrf_storage.Remove(r); } } }