Skip to main content
Memory actions allow you to store and retrieve data in temporary memory storage. This is useful for caching frequently accessed data, passing state between workflow executions, and implementing cache-aside patterns.
Memory storage persists across workflow executions but is cleared when the server restarts. For persistent storage, use Data Operations.

memory_store

Stores data in temporary memory using a key-value pattern.

Key

The unique identifier for storing the data. Use template syntax to create dynamic keys.
Include unique identifiers in your keys to avoid collisions. For example: user_{{ param "user_id" }} or cache_{{ .request_hash }}.

Contents

The data to store. Can be any value, including JSON objects. Use {{ jsonout .action_result }} to store complex objects from previous actions.

Example

Store a user object in memory:
Store a computed value:

memory_fetch

Retrieves data from temporary memory storage using a key.

Key

The key to look up in memory storage.

Example

Retrieve a cached user:
The fetched value is available via {{ .get_cached_user }}. If the key doesn’t exist, the result will be empty.

Common Patterns

Cache-Aside Pattern

Check the cache first, fetch from database if not found, then update the cache:

Session Storage

Store and retrieve user session data:

Rate Limiting Counter

Track request counts for rate limiting:

Temporary Token Storage

Store and validate temporary tokens:

Best Practices

Key Naming: Use consistent key naming conventions with prefixes to organize your cached data. For example: user_, session_, cache_, rate_.
Data Size: Keep stored values reasonably sized. For large datasets, consider storing only essential fields or IDs and fetching full data when needed.
No TTL: Memory storage doesn’t support automatic expiration. Implement your own expiration logic by storing timestamps and checking them during retrieval.

Next Steps

Data Operations

Use persistent database storage for long-term data.

Transformation

Process and transform cached data with JavaScript.

Flow Control

Combine caching with parallel data fetching.

Actions Overview

Learn the fundamentals of ServFlow actions.