Memory
In-process key-value store with LRU eviction, TTL expiration, and namespace support. Platform-agnostic: works in both browser and server flows.
Installation
- Integrated
- Bundled
Add to your flow.json:
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
| Property | Type | Description | More |
|---|---|---|---|
maxSize | integer | Maximum total size in bytes before LRU eviction (default 10 MB) | |
maxEntries | integer | Maximum number of entries before oldest is evicted |
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
set and get
ttl expiration
When to use
| Scenario | Recommended store |
|---|---|
| Caching API responses within a request cycle | Memory: fastest, no I/O |
| Deduplicating events (seen-key tracking) | Memory: in-process, zero overhead |
| Ephemeral session or user state | Memory: TTL support, auto-expiry |
| Sharing state across browser tabs | Not memory: use a server store |
| Persisting data across server restarts | Filesystem or S3 |
Both maxSize and maxEntries can be used together. When either is exceeded, the least-recently-used entry is evicted first.
API
TTL expiration
Pass a TTL in milliseconds as the third argument to set(). Expired entries are cleaned up lazily on the next get():
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:
Testing
Use createMockStore for unit tests. It implements the same interface and tracks all operations: