AI-generated Key Takeaways
-
Apps Script Cache service provides temporary storage for script results, improving performance by avoiding redundant computations or fetches.
-
Two types of caches are available: public caches for shared data and private caches for user-specific information.
-
CacheService
offers methods to access document, script, or user-scoped caches, while theCache
class provides methods for data manipulation within a cache instance, like adding, retrieving, and removing entries. -
Cache entries can have optional expiration times, allowing for automatic removal after a specified duration.
This service allows a script to temporarily cache results that take time to fetch/compute. Public caches are for things that are not dependent on which user is accessing your script. Private caches are for things which are user-specific, like settings or recent activity.
Classes
Name | Brief description |
---|---|
Cache | A reference to a particular cache. |
Cache | Cache |
Cache
Methods
Method | Return type | Brief description |
---|---|---|
get(key) | String | Gets the cached value for the given key, or null if none is found. |
get | Object | Returns a JavaScript Object containing all key/value pairs found in the cache for an array of keys. |
put(key, value) | void | Adds a key/value pair to the cache. |
put(key, value, expirationInSeconds) | void | Adds a key/value pair to the cache, with an expiration time (in seconds). |
put | void | Adds a set of key/value pairs to the cache. |
put | void | Adds a set of key/value pairs to the cache, with an expiration time (in seconds). |
remove(key) | void | Removes an entry from the cache using the given key. |
remove | void | Removes a set of entries from the cache. |
CacheService
Methods
Method | Return type | Brief description |
---|---|---|
get | Cache | Gets the cache instance scoped to the current document and script. |
get | Cache | Gets the cache instance scoped to the script. |
get | Cache | Gets the cache instance scoped to the current user and script. |