Skip to content

Memory store

The memory store is the quickest way to try the package:

import { MemoryStore } from 'limix';
const store = new MemoryStore();

Construct your own instance rather than sharing one across unrelated limiters — it keeps state ownership explicit and makes tests easy to isolate. A pre-built memoryStore singleton is also exported for quick scripts, but prefer new MemoryStore() in application code.

  • Local development
  • Unit and integration tests
  • Scripts and command-line tools
  • A service that intentionally runs as one process

A MemoryStore won’t grow forever. It caps itself at maxEntries (50,000 by default) and opportunistically removes expired entries on an interval (cleanupIntervalMs, 30 seconds by default):

const store = new MemoryStore({ maxEntries: 100_000, cleanupIntervalMs: 10_000 });

If the cap is reached and cleanup can’t free space, store calls throw a RateLimiterStoreError with code MEMORY_CAPACITY_EXCEEDED instead of growing unbounded. Call store.cleanup() to sweep expired entries on demand, or store.clear() to reset all state — useful between test cases.

Memory is not shared between processes or machines. If three application instances each enforce 100 requests, the deployment can accept roughly 300 requests across those independent stores.

Use Redis when the limit needs to apply across instances.