Class MemoryThrottlingCache
- Namespace
- Cuemon.AspNetCore.Http.Throttling
- Assembly
- Cuemon.AspNetCore.dll
Provides a simple in-memory representation of the IThrottlingCache. This class cannot be inherited.
public sealed class MemoryThrottlingCache : ConcurrentDictionary<string, ThrottleRequest>, IDictionary<string, ThrottleRequest>, ICollection<KeyValuePair<string, ThrottleRequest>>, IReadOnlyDictionary<string, ThrottleRequest>, IReadOnlyCollection<KeyValuePair<string, ThrottleRequest>>, IEnumerable<KeyValuePair<string, ThrottleRequest>>, IDictionary, ICollection, IThrottlingCache, IDictionary<string, ThrottleRequest>, ICollection<KeyValuePair<string, ThrottleRequest>>, IEnumerable<KeyValuePair<string, ThrottleRequest>>, IEnumerable
- Inheritance
-
MemoryThrottlingCache
- Implements
- Inherited Members
Examples
The following example shows how to create a MemoryThrottlingCache, add a throttle request for a client, and retrieve the request count from the cache.
using System;
namespace Cuemon.AspNetCore.Http.Throttling;
public static class MemoryThrottlingCacheExample
{
public static void Demonstrate()
{
var cache = new MemoryThrottlingCache();
var request = new ThrottleRequest(new ThrottleQuota(10, TimeSpan.FromMinutes(1)));
cache.TryAdd("client-1", request);
Console.WriteLine(cache["client-1"].Total);
}
}