Cache step
Remember values between Glue job runs and share them between jobs.
The Cache step reads and writes small values that every Glue job in your company can see. Use it to remember things between runs, such as an ID you've already created, a running tally or the time of the last sync, without a round trip to another system.
When to use it
- Remember a lookup. Save the ID another system gave you so the next run doesn't create a duplicate.
- Count things. Add to a tally across runs with Increment.
- Share a value between jobs. One job saves it, another reads it.
For settings and secrets you manage yourself, use private data instead. The cache is for values your jobs work out, and every entry expires.
Set it up
| In the app | data field | What it does |
|---|---|---|
| Operation | operation | Get, Set, Delete or Increment. |
| Key | key | Up to 200 characters. Liquid works, so customer:{{ email }} gives each customer their own entry. |
| Value | value | Set only. Liquid works. |
| Value type | value_type | Set only: String, JSON or Number. JSON and Number are checked before saving. |
| Time to live (seconds) | ttl_seconds | Set and Increment. Defaults to one day (86400). |
| Increment by | by | Increment only. Defaults to 1. Use a negative number to count down. |
| Default value | default_value | Get only. Returned when the key isn't there. Liquid works. |
| Response variable | response_variable | Saves the result. |
Keys are shared by the whole companyEvery Glue job in your company reads and writes the same keys, so give each job's keys a prefix, like
shopify:last_syncorklaviyo:profile:{{ customer_id }}.
What it saves
| Operation | Response variable |
|---|---|
| Get | The value, exactly as it was stored: a string, a number, or the object or array you saved as JSON. A missing key gives null, or the Default value if you set one. |
| Set | The value you saved. |
| Increment | The new number. |
| Delete | true if the key existed, otherwise false. |
Stored values are never run through Liquid when you read them back, so a value containing {{ }} comes back unchanged.
Limits
- 1,000 keys per company. Overwriting an existing key doesn't use another slot, and deleting a key frees one. Expired keys free their slot too.
- Keys are up to 200 characters. Values are up to 64 KB.
- Time to live runs from 1 second to 30 days. Anything outside that range is clamped to the nearest limit.
- Increment works on whole numbers: a key you've only ever incremented, or one you saved with Value type Number. Incrementing a key that doesn't exist yet starts it from 0. Increment keeps an existing key's expiry, and only sets one when the key is new.
When the company is at 1,000 keys, writing a new key fails with an error like cache: this company already has 1000 stored keys; delete some or use shorter TTLs.
Example 1: Create a customer only once
Trigger: Webhook. Another system sends you customers, sometimes more than once.
-
Script: Read the payload
var body = JSON.parse($.default); $.email = (body.email || "").trim().toLowerCase(); -
Cache: Read the cached customer, Operation Get, Key
customer:{{ email }}, Response variablecached_id. -
If Condition: If the customer is new, Condition
$.cached_id === null. Under THEN:- Script: Build the customer, which sets
$.customer_body = JSON.stringify({...}). - API Request: Create the customer,
POSTwith Body{{ customer_body }}, Response variablecustomer_res, Fail on bad response code on. - Script: Save the id:
$.customer_id = String(JSON.parse($.customer_res.body).id); - Cache: Store the customer, Operation Set, Key
customer:{{ email }}, Value{{ customer_id }}, Time to live2592000(30 days).
- Script: Build the customer, which sets
Two copies of the same webhook can arrive at the same moment. To stop both creating the customer, wrap the check in a Lock.
Example 2: Alert when orders pile up
Trigger: Scheduled.
- REST Request: Get open orders from your order system, Response variable
orders_res. - Script: Count the orders:
$.open_count = JSON.parse($.orders_res.body).length; - If Condition: If the count is high, Condition
$.open_count > 50. Under THEN:- Cache: Add to the tally, Operation Increment, Key
orders:high_count, Increment by1, Time to live86400, Response variabletally. - If Condition: If the tally is over the limit, Condition
$.tally >= 3, with a Send Notification step under THEN.
- Cache: Add to the tally, Operation Increment, Key
Tips
- Check for a miss with
=== null(when you haven't set a Default value). - Save objects as JSON. Set Value type to JSON and put
{{ my_json }}in Value, where a script has set$.my_json = JSON.stringify(obj). Get hands you the object back. - Don't cache secrets. Keep API keys in private data.
Updated about 23 hours ago
