Class CacheService
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
خدمة ذاكرة التخزين المؤقت
ذاكرة التخزين المؤقتتسمح لك الخدمة بالوصول إلى ذاكرة تخزين مؤقت لتخزين البيانات على المدى القصير.
تتيح لك هذه الفئة الحصول على مثيل ذاكرة تخزين مؤقت معيّن. تكون ذاكرات التخزين المؤقت العامة مخصّصة للعناصر التي لا تعتمد على المستخدم الذي يصل إلى النص البرمجي. وتكون ذاكرات التخزين المؤقت الخاصة مخصّصة للعناصر التي تخصّ
المستخدم، مثل الإعدادات أو الأنشطة الحديثة.
لا يمكن ضمان استمرار البيانات التي تكتبها في ذاكرة التخزين المؤقت إلى وقت انتهاء صلاحيتها. يجب أن تكون مستعدًا لاسترداد null
من جميع عمليات القراءة.
الطُرق
الطريقة | نوع القيمة التي يتم عرضها | وصف قصير |
getDocumentCache() | Cache | تحصل على مثيل ذاكرة التخزين المؤقت الذي يشمل المستند والنصوص البرمجية الحالية. |
getScriptCache() | Cache | تحصل على مثيل ذاكرة التخزين المؤقت الذي يشمل النص البرمجي. |
getUserCache() | Cache | تحصل على مثيل ذاكرة التخزين المؤقت على مستوى المستخدِم والنصوص البرمجية الحاليَين. |
مستندات تفصيلية
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. إنّ Java هي علامة تجارية مسجَّلة لشركة Oracle و/أو شركائها التابعين.
تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-07-26 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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"]]