Skip to main content

Memory

Source code Package

In-process key-value store with LRU eviction, TTL expiration, and namespace support. Platform-agnostic: works in both browser and server flows.

When to use

ScenarioRecommended store
Caching API responses within a request cycleMemory: fastest, no I/O
Deduplicating events (seen-key tracking)Memory: in-process, zero overhead
Ephemeral session or user stateMemory: TTL support, auto-expiry
Sharing state across browser tabsNot memory: use a server store
Persisting data across server restartsFilesystem or S3

Setup

Install the package:

Loading...

Configure in your code:

Loading...

Configuration

PropertyTypeDescriptionMore
maxSize*integerMaximum total size in bytes before LRU eviction (default 10 MB)
maxEntriesintegerMaximum number of entries before oldest is evicted
* Required fields

Both limits can be used together. When either is exceeded, the least-recently-used entry is evicted first.

API

Loading...

TTL expiration

Pass a TTL in milliseconds as the third argument to set(). Expired entries are cleaned up lazily on the next get():

Loading...

Entries without a TTL never expire.

LRU eviction

When the store exceeds maxSize or maxEntries, the least-recently-used entries are evicted to make room. Calling get() refreshes an entry's position, so frequently accessed entries survive longer.

Size is estimated from JSON.stringify(value).length + key.length.

Namespace utility

Use withNamespace to scope keys for different components sharing one store:

Loading...

Testing

Use createMockStore for unit tests. It implements the same interface and tracks all operations:

Loading...
💡 Need implementation support?
elbwalker offers hands-on support: setup review, measurement planning, destination mapping, and live troubleshooting. Book a 2-hour session (€399)