Memory Store
The memory store is the default storage backend. It keeps rate limit data in memory, making it fast but non-persistent.
Usage
The memory store is used by default when no store is specified:
import { hitlimit } from '@joint-ops/hitlimit'
// Memory store is the default
app.use(hitlimit({ limit: 100, window: '1m' })) Or explicitly configure it:
import { hitlimit, memoryStore } from '@joint-ops/hitlimit'
app.use(hitlimit({
limit: 100,
window: '1m',
store: memoryStore({
cleanupInterval: 60000 // Clean expired entries every 60s
})
})) Options
| Option | Type | Default | Description |
|---|---|---|---|
cleanupInterval | number | 60000 | Interval (ms) to clean expired entries |
Characteristics
- Speed: Fastest option - no I/O overhead
- Persistence: Data is lost on restart
- Scalability: Not shared between instances
- Memory: Grows with unique keys; auto-cleanup removes expired entries
When to Use
- Development and testing
- Single-instance deployments
- When persistence is not required
- Low-traffic applications
Limitations
- Rate limits reset on server restart
- Not suitable for multi-server deployments
- Memory usage increases with unique client keys