コード例 #1
0
        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);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
        /// <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
            });
        }
コード例 #4
0
        /// <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
            };
        }
コード例 #5
0
        public void Remove(string id)
        {
            var entry = new ThrottleCounterWrapper();

            cache.TryRemove(id, out entry);
        }
コード例 #6
0
 public void Remove(string id)
 {
     var entry = new ThrottleCounterWrapper();
     cache.TryRemove(id, out entry);
 }