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 appdata fieldWhat it does
OperationoperationGet, Set, Delete or Increment.
KeykeyUp to 200 characters. Liquid works, so customer:{{ email }} gives each customer their own entry.
ValuevalueSet only. Liquid works.
Value typevalue_typeSet only: String, JSON or Number. JSON and Number are checked before saving.
Time to live (seconds)ttl_secondsSet and Increment. Defaults to one day (86400).
Increment bybyIncrement only. Defaults to 1. Use a negative number to count down.
Default valuedefault_valueGet only. Returned when the key isn't there. Liquid works.
Response variableresponse_variableSaves the result.
📘

Keys are shared by the whole company

Every Glue job in your company reads and writes the same keys, so give each job's keys a prefix, like shopify:last_sync or klaviyo:profile:{{ customer_id }}.

What it saves

OperationResponse variable
GetThe 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.
SetThe value you saved.
IncrementThe new number.
Deletetrue 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.

  1. Script: Read the payload

    var body = JSON.parse($.default);
    $.email = (body.email || "").trim().toLowerCase();
  2. Cache: Read the cached customer, Operation Get, Key customer:{{ email }}, Response variable cached_id.

  3. If Condition: If the customer is new, Condition $.cached_id === null. Under THEN:

    1. Script: Build the customer, which sets $.customer_body = JSON.stringify({...}).
    2. API Request: Create the customer, POST with Body {{ customer_body }}, Response variable customer_res, Fail on bad response code on.
    3. Script: Save the id: $.customer_id = String(JSON.parse($.customer_res.body).id);
    4. Cache: Store the customer, Operation Set, Key customer:{{ email }}, Value {{ customer_id }}, Time to live 2592000 (30 days).

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.

  1. REST Request: Get open orders from your order system, Response variable orders_res.
  2. Script: Count the orders: $.open_count = JSON.parse($.orders_res.body).length;
  3. If Condition: If the count is high, Condition $.open_count > 50. Under THEN:
    1. Cache: Add to the tally, Operation Increment, Key orders:high_count, Increment by 1, Time to live 86400, Response variable tally.
    2. If Condition: If the tally is over the limit, Condition $.tally >= 3, with a Send Notification step under THEN.

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.

← All Glue step guides


Did this page help you?