Class CacheService
컬렉션을 사용해 정리하기
내 환경설정을 기준으로 콘텐츠를 저장하고 분류하세요.
캐시서비스
Cache서비스를 사용하면 데이터를 단기 저장하기 위해 캐시에 액세스할 수 있습니다.
이 클래스를 사용하면 특정 캐시 인스턴스를 가져올 수 있습니다. 공개 캐시는 스크립트에 액세스하는 사용자에 종속되지 않는 항목에 사용됩니다. 비공개 캐시는 설정이나 최근 활동과 같이 사용자별인 항목에 사용됩니다.
캐시에 쓰는 데이터는 만료 시간까지 유지되지 않을 수 있습니다. 모든 읽기에서 null
를 가져올 준비가 되어 있어야 합니다.
자세한 문서
getDocumentCache()
현재 문서 및 스크립트로 범위가 지정된 캐시 인스턴스를 가져옵니다. 문서 캐시는 스크립트가 포함된 현재 문서에만 적용됩니다. 이를 사용하여 현재 문서와 관련된 스크립트 정보를 저장합니다. 이 메서드가 포함된 문서의 컨텍스트 외부에서 호출되면 (예: 독립형 스크립트 또는 웹 앱에서) 이 메서드는 null
를 반환합니다.
// Gets a cache that is specific to the current document containing the script
const cache = CacheService.getDocumentCache();
리턴
Cache
: 문서 캐시 인스턴스 또는 포함된 문서가 없는 경우 null
getScriptCache()
스크립트로 범위가 지정된 캐시 인스턴스를 가져옵니다. 스크립트 캐시는 스크립트의 모든 사용자에게 공통적입니다. 현재 사용자와 관련 없는 정보를 저장하는 데 사용합니다.
// Gets a cache that is common to all users of the script
const cache = CacheService.getScriptCache();
리턴
Cache
: 스크립트 캐시 인스턴스
getUserCache()
현재 사용자 및 스크립트로 범위가 지정된 캐시 인스턴스를 가져옵니다. 사용자 캐시는 스크립트의 현재 사용자에 따라 다릅니다. 이를 사용하여 현재 사용자와 관련된 스크립트 정보를 저장합니다.
// Gets a cache that is specific to the current user of the script
const cache = CacheService.getUserCache();
리턴
Cache
: 사용자 캐시 인스턴스
달리 명시되지 않는 한 이 페이지의 콘텐츠에는 Creative Commons Attribution 4.0 라이선스에 따라 라이선스가 부여되며, 코드 샘플에는 Apache 2.0 라이선스에 따라 라이선스가 부여됩니다. 자세한 내용은 Google Developers 사이트 정책을 참조하세요. 자바는 Oracle 및/또는 Oracle 계열사의 등록 상표입니다.
최종 업데이트: 2025-07-26(UTC)
[null,null,["최종 업데이트: 2025-07-26(UTC)"],[[["\u003cp\u003e\u003ccode\u003eCacheService\u003c/code\u003e provides short-term storage for script data, offering document, script, and user-specific scopes.\u003c/p\u003e\n"],["\u003cp\u003eData stored using \u003ccode\u003eCacheService\u003c/code\u003e is not guaranteed to persist and may return \u003ccode\u003enull\u003c/code\u003e when retrieved.\u003c/p\u003e\n"],["\u003cp\u003eThree cache instances are available: \u003ccode\u003egetDocumentCache()\u003c/code\u003e for document-specific data, \u003ccode\u003egetScriptCache()\u003c/code\u003e for script-wide data, and \u003ccode\u003egetUserCache()\u003c/code\u003e for user-specific data.\u003c/p\u003e\n"],["\u003cp\u003eWhen using \u003ccode\u003egetDocumentCache()\u003c/code\u003e, it returns \u003ccode\u003enull\u003c/code\u003e if called outside a document context (standalone script or web app).\u003c/p\u003e\n"]]],[],null,["# Class CacheService\n\nCacheService\n\nCacheService allows you to access a cache for short term storage of data.\n\nThis class lets you get a specific cache instance. Public caches are for things that are not\ndependent on which user is accessing your script. Private caches are for things which are\nuser-specific, like settings or recent activity.\n\nThe data you write to the cache is not guaranteed to persist until its expiration time. You\nmust be prepared to get back `null` from all reads. \n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------|---------------------------------------------|--------------------------------------------------------------------|\n| [getDocumentCache()](#getDocumentCache()) | [Cache](/apps-script/reference/cache/cache) | Gets the cache instance scoped to the current document and script. |\n| [getScriptCache()](#getScriptCache()) | [Cache](/apps-script/reference/cache/cache) | Gets the cache instance scoped to the script. |\n| [getUserCache()](#getUserCache()) | [Cache](/apps-script/reference/cache/cache) | Gets the cache instance scoped to the current user and script. |\n\nDetailed documentation\n----------------------\n\n### `get``Document``Cache()`\n\nGets the cache instance scoped to the current document and script. Document caches are specific\nto the current document which contains the script. Use these to store script information that\nis specific to the current document. If this method is called outside of the context of a\ncontaining document (such as from a standalone script or web app), this method returns `null`.\n\n```javascript\n// Gets a cache that is specific to the current document containing the script\nconst cache = CacheService.getDocumentCache();\n```\n\n#### Return\n\n\n[Cache](/apps-script/reference/cache/cache) --- a document cache instance, or `null` if there is no containing document\n\n*** ** * ** ***\n\n### `get``Script``Cache()`\n\nGets the cache instance scoped to the script. Script caches are common to all users of the\nscript. Use these to store information that is not specific to the current user.\n\n```javascript\n// Gets a cache that is common to all users of the script\nconst cache = CacheService.getScriptCache();\n```\n\n#### Return\n\n\n[Cache](/apps-script/reference/cache/cache) --- a script cache instance\n\n*** ** * ** ***\n\n### `get``User``Cache()`\n\nGets the cache instance scoped to the current user and script. User caches are specific to the\ncurrent user of the script. Use these to store script information that is specific to the\ncurrent user.\n\n```javascript\n// Gets a cache that is specific to the current user of the script\nconst cache = CacheService.getUserCache();\n```\n\n#### Return\n\n\n[Cache](/apps-script/reference/cache/cache) --- a user cache instance"]]