MCPcopy
hub / github.com/express-rate-limit/express-rate-limit / init

Method init

source/memory-store.ts:60–78  ·  view source on GitHub ↗

* Method that initializes the store. * * @param options {Options} - The options used to setup the middleware.

(options: Options)

Source from the content-addressed store, hash-verified

58 * @param options {Options} - The options used to setup the middleware.
59 */
60 init(options: Options): void {
61 // Get the duration of a window from the options.
62 this.windowMs = options.windowMs
63
64 // check for a valid value
65 this.validations?.windowMs(this.windowMs)
66
67 // Indicates that init was called more than once.
68 // Could happen if a store was shared between multiple instances.
69 if (this.interval) clearInterval(this.interval)
70
71 // Reset all clients left in previous every `windowMs`.
72 this.interval = setInterval(() => {
73 this.clearExpired()
74 }, this.windowMs)
75
76 // Cleaning up the interval will be taken care of by the `shutdown` method.
77 this.interval.unref?.()
78 }
79
80 /**
81 * Method to fetch a client's hit count and reset time.

Callers 1

rateLimitFunction · 0.45

Calls 1

clearExpiredMethod · 0.95

Tested by

no test coverage detected