You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
You can set an expiration time for a record by passing a TTL (Time-To-Live) option as the third argument to the `set` method. The TTL value is specified in seconds:
57
+
58
+
```javascript
59
+
exportdefaultdefineComponent({
60
+
props: {
61
+
data: { type:"data_store" },
62
+
},
63
+
asyncrun({ steps, $ }) {
64
+
// Store a temporary value that will expire after 1 hour (3600 seconds)
## TTL use case: temporary caching and rate limiting
288
+
289
+
TTL functionality is particularly useful for implementing temporary caching and rate limiting. Here's an example of a simple rate limiter that prevents a user from making more than 5 requests per hour:
290
+
291
+
```javascript
292
+
exportdefaultdefineComponent({
293
+
props: {
294
+
data: { type:"data_store" },
295
+
},
296
+
asyncrun({ steps, $ }) {
297
+
constuserId=steps.trigger.event.userId;
298
+
constrateKey=`ratelimit:${userId}`;
299
+
300
+
// Try to get current rate limit counter
301
+
let requests =awaitthis.data.get(rateKey);
302
+
303
+
if (requests ===undefined) {
304
+
// First request from this user in the time window
305
+
awaitthis.data.set(rateKey, 1, { ttl:3600 }); // Expire after 1 hour
This pattern can be extended for various temporary caching scenarios like:
322
+
- Session tokens with automatic expiration
323
+
- Short-lived feature flags
324
+
- Temporary access grants
325
+
- Time-based promotional codes
326
+
245
327
## Data store limitations
246
328
247
329
Data Stores are only currently available in Node.js and Python steps. They are not yet available [Bash](/workflows/building-workflows/code/bash/) or [Go](/workflows/building-workflows/code/go/).
TTL functionality is currently only available in Node.js code steps. If you need to set expiration on records from Python steps, you'll need to use a Node.js step to set or update the TTL.
49
+
</Callout>
50
+
51
+
For temporary data that should automatically expire, you can use a Node.js step with TTL functionality. See the [Node.js documentation](/workflows/building-workflows/code/nodejs/using-data-stores/#setting-expiration-ttl-for-records) for details on how to use TTL with data stores.
52
+
45
53
## Retrieving keys
46
54
47
55
Fetch all the keys in a given data store using the `keys` method:
Copy file name to clipboardExpand all lines: docs-v2/pages/workflows/data-management/data-stores.mdx
+20-1Lines changed: 20 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,9 +13,10 @@ import VideoPlayer from "@/components/VideoPlayer";
13
13
Data stores are useful for:
14
14
15
15
- Storing and retrieving data at a specific key
16
+
- Setting automatic expiration times for temporary data (TTL)
16
17
- Counting or summing values over time
17
18
- Retrieving JSON-serializable data across workflow executions
18
-
- Caching
19
+
- Caching and rate limiting
19
20
- And any other case where you'd use a key-value store
20
21
21
22
You can connect to the same data store across workflows, so they're also great for sharing state across different services.
@@ -41,6 +42,7 @@ Configure the action:
41
42
1.**Select or create a Data Store** — create a new data store or choose an existing data store.
42
43
2.**Key** - the unique ID for this data that you'll use for lookup later
43
44
3.**Value** - The data to store at the specified `key`
45
+
4.**Time to Live (TTL)** - (Optional) The number of seconds until this record expires and is automatically deleted. Leave blank for records that should not expire.
44
46
45
47

46
48
@@ -74,6 +76,23 @@ Configure the action:
74
76
75
77

76
78
79
+
### Setting or updating record expiration (TTL)
80
+
81
+
You can set automatic expiration times for records using the **Update record expiration** action:
82
+
83
+
1. Add a new step to your workflow.
84
+
2. Search for the **Data Stores** app and select it.
85
+
3. Select the **Update record expiration** pre-built action.
86
+
87
+
Configure the action:
88
+
89
+
1.**Select a Data Store** - select the data store containing the record to modify
90
+
2.**Key** - the key for the record you want to update the expiration for
91
+
3.**Expiration Type** - choose from preset expiration times (1 hour, 1 day, 1 week, etc.) or select "Custom value" to enter a specific time in seconds
92
+
4.**Custom TTL (seconds)** - (only if "Custom value" is selected) enter the number of seconds until the record expires
93
+
94
+
To remove expiration from a record, select "No expiration" as the expiration type.
95
+
77
96
### Deleting Data
78
97
79
98
To delete a single record from your data store, use the **Delete a single record** action in a step:
0 commit comments