Skip to content

super simple rate limiter, integrated with lru-cache library

Notifications You must be signed in to change notification settings

Galcarmi/RateLimiter

Repository files navigation

SimpleRateLimiter

SimpleJSRateLimitersuper is a simple RateLimiter integrated with lru cache package.

const { RateLimiterSingleton } = require("custom-rate-limiter");

const rateLimiter = RateLimiterSingleton.GetInstance();

//SetRateLimitOptions(timelimit in milliseconds, maximumRequestInTimeLimit);
rateLimiter.SetRateLimitOptions(4000, 2);

//ThrowLimitExceptionIfNecessary('unique identifier for a specific user')
rateLimiter.ThrowLimitExceptionIfNecessary("2");
rateLimiter.ThrowLimitExceptionIfNecessary("3");

//should do nothing

////////////////////////////////////////////////////////////////////////////
rateLimiter.SetRateLimitOptions(4000, 2);
rateLimiter.ThrowLimitExceptionIfNecessary("2");
rateLimiter.ThrowLimitExceptionIfNecessary("2");
rateLimiter.ThrowLimitExceptionIfNecessary("2");

//should throw rate limit exception

About

super simple rate limiter, integrated with lru-cache library

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published