set
  • 30 Oct 2020
  • 1 Minute to read
  • Contributors
  • Dark
    Light
  • PDF

set

  • Dark
    Light
  • PDF

Article Summary

Description

Inserts an object into cache, persisting for the lifetime of your app or until cleared.


Input Parameters

NameTypeRequiredDescription
keyTextYesUnique object identifier
valueAnyYesObject to store

Returns

No return value.


Examples

// store numeric value in cache
cache.set("score", 64);
// prepare a custom person object
var person = {
    "firstName": "Caleb",
    "age": 25,
    "id": system.newId()
};

// store person object in cache
cache.set("myPerson", person);
// later, we can get same person from cache
var person = cache.get("myPerson");

// print person's first name to the debug console
debug.log(person.firstName);

Remarks

Use this function when you want to store information across script executions.

Definition

Cache is a programming term referring to a simple database of information. A cache is a collection of associated key-value pairs. The key must be a unique identifier and the value is any object you want to store. Once stored, you can retrieve these objects using their keys.


What's Next