Skip to content

Latest commit

 

History

History
26 lines (18 loc) · 856 Bytes

README.md

File metadata and controls

26 lines (18 loc) · 856 Bytes

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