Memory
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
| 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 |
Setup
- Integrated
- Bundled
Install the package:
Configure in your code:
Add to your flow.json:
Configuration
| 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 |
Both limits 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: