Skip to content

A generic rate limiter, Useful for API clients, web crawling, or other tasks that need to be throttled...

License

Notifications You must be signed in to change notification settings

laget-se/laget.Limiter

Folders and files

NameName
Last commit message
Last commit date
Jan 20, 2024
Dec 8, 2020
Oct 22, 2024
Nov 4, 2024
Dec 8, 2020
Dec 8, 2020
Dec 8, 2020
Dec 23, 2020
Jun 3, 2024
Dec 8, 2020

Repository files navigation

laget.Limiter

A generic rate limiter, Useful for API clients, web crawling, or other tasks that need to be throttled...

Nuget Nuget

Configuration

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();

Usage

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);

Stores

Mongo

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();

About

A generic rate limiter, Useful for API clients, web crawling, or other tasks that need to be throttled...

Topics

Resources

License

Stars

Watchers

Forks

Languages