public void Save(string id, ThrottleCounter throttleCounter, TimeSpan expirationTime) { var entry = new ThrottleCounterWrapper { ExpirationTime = expirationTime, Timestamp = throttleCounter.Timestamp, TotalRequests = throttleCounter.TotalRequests }; cache.AddOrUpdate(id, entry, (k, e) => entry); }
/// <summary> /// Insert or update /// </summary> /// <param name="id"> /// The id. /// </param> /// <returns> /// The <see cref="ThrottleCounter"/>. /// </returns> public ThrottleCounter?FirstOrDefault(string id) { var entry = new ThrottleCounterWrapper(); if (cache.TryGetValue(id, out entry)) { // remove expired entry if (entry.Timestamp + entry.ExpirationTime < DateTime.UtcNow) { cache.TryRemove(id, out entry); return(null); } } return(new ThrottleCounter { Timestamp = entry.Timestamp, TotalRequests = entry.TotalRequests }); }
/// <summary> /// Insert or update /// </summary> /// <param name="id"> /// The id. /// </param> /// <returns> /// The <see cref="ThrottleCounter"/>. /// </returns> public ThrottleCounter? FirstOrDefault(string id) { var entry = new ThrottleCounterWrapper(); if (cache.TryGetValue(id, out entry)) { // remove expired entry if (entry.Timestamp + entry.ExpirationTime < DateTime.UtcNow) { cache.TryRemove(id, out entry); return null; } } return new ThrottleCounter { Timestamp = entry.Timestamp, TotalRequests = entry.TotalRequests }; }
public void Remove(string id) { var entry = new ThrottleCounterWrapper(); cache.TryRemove(id, out entry); }