Cache Service
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Bộ nhớ đệm
Dịch vụ này cho phép tập lệnh tạm thời lưu kết quả vào bộ nhớ đệm khi cần thời gian để tìm nạp/tính toán. Bộ nhớ đệm công khai dành cho những nội dung không phụ thuộc vào người dùng nào đang truy cập vào tập lệnh của bạn. Bộ nhớ đệm riêng tư dành cho những nội dung dành riêng cho người dùng, chẳng hạn như chế độ cài đặt hoặc hoạt động gần đây.
Lớp
Tên | Mô tả ngắn |
Cache | Tham chiếu đến một bộ nhớ đệm cụ thể. |
CacheService | Dịch vụbộ nhớ đệm cho phép bạn truy cập vào bộ nhớ đệm để lưu trữ dữ liệu trong thời gian ngắn. |
Phương thức
Phương thức | Loại dữ liệu trả về | Mô tả ngắn |
get(key) | String | Lấy giá trị được lưu vào bộ nhớ đệm cho khoá đã cho hoặc null nếu không tìm thấy giá trị nào. |
getAll(keys) | Object | Trả về một Đối tượng JavaScript chứa tất cả các cặp khoá/giá trị tìm thấy trong bộ nhớ đệm cho một mảng khoá. |
put(key, value) | void | Thêm một cặp khoá/giá trị vào bộ nhớ đệm. |
put(key, value, expirationInSeconds) | void | Thêm một cặp khoá/giá trị vào bộ nhớ đệm, với thời gian hết hạn (tính bằng giây). |
putAll(values) | void | Thêm một tập hợp các cặp khoá/giá trị vào bộ nhớ đệm. |
putAll(values, expirationInSeconds) | void | Thêm một tập hợp các cặp khoá/giá trị vào bộ nhớ đệm, với thời gian hết hạn (tính bằng giây). |
remove(key) | void | Xoá một mục khỏi bộ nhớ đệm bằng khoá đã cho. |
removeAll(keys) | void | Xoá một tập hợp các mục nhập khỏi bộ nhớ đệm. |
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-07-26 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-26 UTC."],[[["\u003cp\u003eApps Script Cache service provides temporary storage for script results, improving performance by avoiding redundant computations or fetches.\u003c/p\u003e\n"],["\u003cp\u003eTwo types of caches are available: public caches for shared data and private caches for user-specific information.\u003c/p\u003e\n"],["\u003cp\u003e\u003ccode\u003eCacheService\u003c/code\u003e offers methods to access document, script, or user-scoped caches, while the \u003ccode\u003eCache\u003c/code\u003e class provides methods for data manipulation within a cache instance, like adding, retrieving, and removing entries.\u003c/p\u003e\n"],["\u003cp\u003eCache entries can have optional expiration times, allowing for automatic removal after a specified duration.\u003c/p\u003e\n"]]],[],null,["# Cache Service\n\nCache\n\nThis service allows a script to temporarily cache results that take time to\nfetch/compute. Public caches are for things that are not dependent on which user\nis accessing your script. Private caches are for things which are user-specific,\nlike settings or recent activity.\n\nClasses\n-------\n\n| Name | Brief description |\n|------------------------------------------------------------|---------------------------------------------------------------------------|\n| [Cache](/apps-script/reference/cache/cache) | A reference to a particular cache. |\n| [CacheService](/apps-script/reference/cache/cache-service) | CacheService allows you to access a cache for short term storage of data. |\n\n[Cache](/apps-script/reference/cache/cache)\n-------------------------------------------\n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------------------------------------------------|-------------|-----------------------------------------------------------------------------------------------------|\n| [get(key)](/apps-script/reference/cache/cache#get(String)) | `String` | Gets the cached value for the given key, or `null` if none is found. |\n| [getAll(keys)](/apps-script/reference/cache/cache#getAll(String)) | `Object` | Returns a JavaScript Object containing all key/value pairs found in the cache for an array of keys. |\n| [put(key, value)](/apps-script/reference/cache/cache#put(String,String)) | `void` | Adds a key/value pair to the cache. |\n| [put(key, value, expirationInSeconds)](/apps-script/reference/cache/cache#put(String,String,Integer)) | `void` | Adds a key/value pair to the cache, with an expiration time (in seconds). |\n| [putAll(values)](/apps-script/reference/cache/cache#putAll(Object)) | `void` | Adds a set of key/value pairs to the cache. |\n| [putAll(values, expirationInSeconds)](/apps-script/reference/cache/cache#putAll(Object,Integer)) | `void` | Adds a set of key/value pairs to the cache, with an expiration time (in seconds). |\n| [remove(key)](/apps-script/reference/cache/cache#remove(String)) | `void` | Removes an entry from the cache using the given key. |\n| [removeAll(keys)](/apps-script/reference/cache/cache#removeAll(String)) | `void` | Removes a set of entries from the cache. |\n\n[CacheService](/apps-script/reference/cache/cache-service)\n----------------------------------------------------------\n\n### Methods\n\n| Method | Return type | Brief description |\n|-------------------------------------------------------------------------------------|---------------------------------------------|--------------------------------------------------------------------|\n| [getDocumentCache()](/apps-script/reference/cache/cache-service#getDocumentCache()) | [Cache](/apps-script/reference/cache/cache) | Gets the cache instance scoped to the current document and script. |\n| [getScriptCache()](/apps-script/reference/cache/cache-service#getScriptCache()) | [Cache](/apps-script/reference/cache/cache) | Gets the cache instance scoped to the script. |\n| [getUserCache()](/apps-script/reference/cache/cache-service#getUserCache()) | [Cache](/apps-script/reference/cache/cache) | Gets the cache instance scoped to the current user and script. |"]]