Skip to main content
Backend scripts have access to a Redis-backed key-value cache via the cache global. Every key is automatically scoped to the current brand — scripts can never read or write keys belonging to another brand. Values are JSON-serialised, so you can store strings, numbers, booleans, arrays, and plain objects.

cache.get(key)

Retrieve a value from the cache.
var count = cache.get('page_views');
if (count !== null) {
  setVariable('views', count);
}
ParameterTypeDescription
keystringCache key
Returns: The stored value, or null if the key does not exist or has expired.

cache.set(key, value, ttlSeconds?)

Store a value in the cache with an optional TTL.
cache.set('last_visit', new Date().toISOString(), 3600);
ParameterTypeDefaultDescription
keystringCache key
valueanyValue to store (JSON-serialised)
ttlSecondsnumber3600Time-to-live in seconds
Returns: true on success, false if the brand key limit was reached or an error occurred.

cache.del(key)

Delete a key from the cache.
cache.del('last_visit');
ParameterTypeDescription
keystringCache key
Returns: true on success.

cache.has(key)

Check whether a key exists in the cache.
if (cache.has('onboarding_complete')) {
  redirect('/dashboard');
}
ParameterTypeDescription
keystringCache key
Returns: true if the key exists, false otherwise.

cache.setIfAbsent(key, value, ttlSeconds?)

Write a value only if the key does not already exist. Useful for debouncing and deduplication.
var isNew = cache.setIfAbsent('email_sent:' + email, true, 86400);
if (isNew) {
  // First time — send the email
}
ParameterTypeDefaultDescription
keystringCache key
valueanyValue to store
ttlSecondsnumber3600Time-to-live in seconds
Returns: true if the value was written (key was absent), false if the key already existed.

cache.increment(key, amount?, ttlSeconds?)

Atomically increment a numeric value. Creates the key with the given amount if it doesn’t exist.
var views = cache.increment('page:home:views', 1, 86400);
setVariable('view_count', views);
ParameterTypeDefaultDescription
keystringCache key
amountnumber1Value to add (can be negative or float)
ttlSecondsnumberOptional TTL to set/refresh
Returns: The new numeric value after incrementing.
Limits per brand:
  • 50,000 keys maximum per brand
  • 512 bytes maximum value size
  • 1-hour maximum TTL
  • 20 cache operations per script execution
Cache keys must match the pattern [a-zA-Z0-9_.:-] and be at most 200 characters long. Keys that don’t match will throw an error.