A generic rate limiter, Useful for API clients, web crawling, or other tasks that need to be throttled...
$ dotnet add package laget.LimiterA generic rate limiter, Useful for API clients, web crawling, or other tasks that need to be throttled...
This example is shown using Autofac since this is the go-to IoC for us.
builder.Register<IAuthorizationLimit>(c =>
new AuthorizationLimit(new MemoryStore(),
new StandardLimit(300, TimeSpan.FromHours(3)))
).SingleInstance();
You can specifiy that a limiter should be used by the following
_limiter.Limit(() =>
{
...
});
You can also specify that a kown amount of call will be hit by the following
_limiter.Limit(2, () =>
{
...
});
You can aslo specify additional calls by the following
limiter.Limit(() =>
{
limiter.Register(3);
});
You can aslo use it asynchronous by the following
await limiter.LimitAsync(() => Task.CompletedTask);
This example is shown using Autofac since this is the go-to IoC for us.
builder.Register<ISomeLimit>(c =>
new AuthorizationLimit(new MongoStore(new MongoUrl(c.Resolve<IConfiguration>().GetConnectionString("MongoConnectionString")), "authorization.calls"),
new StandardLimit(300, TimeSpan.FromHours(3)))
).SingleInstance();