Class CacheService | Apps Script | Google for Developers (original) (raw)
Class CacheService
Stay organized with collections Save and categorize content based on your preferences.
CacheService
CacheService allows you to access a cache for short term storage of data.
This class lets you get a specific cache instance. 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.
The data you write to the cache is not guaranteed to persist until its expiration time. You must be prepared to get back null
from all reads.
Methods
Method | Return type | Brief description |
---|---|---|
getDocumentCache() | Cache | Gets the cache instance scoped to the current document and script. |
getScriptCache() | Cache | Gets the cache instance scoped to the script. |
getUserCache() | Cache | Gets the cache instance scoped to the current user and script. |
Detailed documentation
getDocumentCache()
Gets the cache instance scoped to the current document and script. Document caches are specific to the current document which contains the script. Use these to store script information that is specific to the current document. If this method is called outside of the context of a containing document (such as from a standalone script or web app), this method returns null
.
// Gets a cache that is specific to the current document containing the script const cache = CacheService.getDocumentCache();
Return
[Cache](/apps-script/reference/cache/cache)
— a document cache instance, or null
if there is no containing document
getScriptCache()
Gets the cache instance scoped to the script. Script caches are common to all users of the script. Use these to store information that is not specific to the current user.
// Gets a cache that is common to all users of the script const cache = CacheService.getScriptCache();
Return
[Cache](/apps-script/reference/cache/cache)
— a script cache instance
getUserCache()
Gets the cache instance scoped to the current user and script. User caches are specific to the current user of the script. Use these to store script information that is specific to the current user.
// Gets a cache that is specific to the current user of the script const cache = CacheService.getUserCache();
Return
[Cache](/apps-script/reference/cache/cache)
— a user cache instance
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2024-12-02 UTC.