Class CacheService Stay organized with collections Save and categorize content based on your preferences.
Page Summary
CacheService provides access to caches for short-term data storage.
You can obtain specific cache instances for public (script-wide) or private (user-specific or document-specific) data.
Data stored in the cache is not guaranteed to persist until its expiration time, and reads might return
null.The CacheService offers methods to get caches scoped to the document, script, or current user.
Cache
This class lets you get a specific cache instance. Public caches are for things that are notdependent on which user is accessing your script. Private caches are for things which areuser-specific, like settings or recent activity.
The data you write to the cache is not guaranteed to persist until its expiration time. Youmust be prepared to get backnull from all reads.
Methods
| Method | Return type | Brief description |
|---|---|---|
get | Cache|null | 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. |
Detailed documentation
getDocumentCache()
Gets the cache instance scoped to the current document and script. Document caches are specificto the current document which contains the script. Use these to store script information thatis specific to the current document. If this method is called outside of the context of acontaining document (such as from a standalone script or web app), this method returnsnull.
// Gets a cache that is specific to the current document containing the scriptconstcache=CacheService.getDocumentCache();
Return
Cache|null — a document cache instance, ornull if there is no containing document
getScriptCache()
Gets the cache instance scoped to the script. Script caches are common to all users of thescript. Use these to store information that is not specific to the current user.
// Gets a cache that is common to all users of the scriptconstcache=CacheService.getScriptCache();
Return
Cache — a script cache instance
getUserCache()
Gets the cache instance scoped to the current user and script. User caches are specific to thecurrent user of the script. Use these to store script information that is specific to thecurrent user.
// Gets a cache that is specific to the current user of the scriptconstcache=CacheService.getUserCache();
Return
Cache — a user cache instance
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-12-11 UTC.