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.

Installation

Loading...
Loading...

Configuration

This store uses the standard store config wrapper (consent, data, env, id, ...). For the shared fields see store configuration. Package-specific fields live under config.settings and are listed below.

Settings

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

Mapping

This package does not define custom rule-level settings. For the standard rule fields (consent, condition, data, batch, name, policy) see mapping.

Examples

get hit

Event
Out

set and get

Event
Out

ttl expiration

Event
Out

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

Both maxSize and maxEntries 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)