Cache
Temporary cache with TTL support
Key-value storage that expires, scoped per script. Default TTL is one hour. For API responses and computed values.
Methods
Cache.get(key)AnyGet a cached value. Returns null if expired or missing.
- key String required
Cache.set(key, value, options?)Cache a value.
- key String required
Scoped to this script.
- value Any required
Any JSON-serialisable value.
- options Any
- expiry Duration
How long it stays valid. Default one hour.
- expiry Duration
Cache.has(key)BooleanCheck if a cached value exists and has not expired.
- key String required
Cache.delete(key)Removes the entry. Same shape as Storage.delete and Keychain.delete.
- key String required
Scoped to this script.
Examples
Caching API data
let data = Cache.get("weather");
if (!data) {
const res = Http.get("https://api.weather.com/now");
data = res.json;
Cache.set("weather", data, {
expiry: Duration.minutes(30)
});
}