الموارد · 63

التخزين المؤقت لبروتوكول HTTP: حماية الاستجابات المخصصة

فصل ذاكرة التخزين المؤقت المشتركة، والخاصة، وذاكرة التخزين المؤقت للتطبيق، وفحص المفاتيح، وإعادة التحقق من صحتها، وإبطالها بعد تغييرات حقوق الوصول.

مُحدَّث · 7 min

ممر آمن للخوادم والشبكات دون أشخاص رسم توضيحي تحريري مولّد بالذكاء الاصطناعي

ما يُساعد هذا الدليل على تحقيقه

  • طبقات الجرد
  • اختيار مدة الاحتفاظ
  • فحص المفاتيح
  • إعادة التحقق والتغيير

فحص سريع

  • هل يعني عدم وجود ذاكرة تخزين مؤقت عدم الاحتفاظ بأي شيء؟
  • هل يحمي Vary حقوق الوصول؟
  • هل يجب تخزين كل واجهة برمجة تطبيقات مؤقتًا؟

طريقة خطوة بخطوة

  1. 1

    طبقات الجرد

    سرد ذاكرات التخزين المؤقت للمتصفح، وشبكة توصيل المحتوى، والوكيل، وعامل الخدمة، والتطبيق. تصنيف الاستجابات العامة والمخصصة. لا تصف سياسة HTTP تلقائيًا التخزين المؤقت المُنفذ في التعليمات البرمجية.

    المُخرَج: مخطط الطبقات والمالكين.

  2. 2

    اختيار مدة الاحتفاظ

    RFC 9111 يميز بين التوجيهات: no-cache يتطلب التحقق قبل إعادة الاستخدام، no-store يمنع تخزين HTTP ذي الصلة، وunqualified private يستبعد التخزين المشترك. لا يضمن أي منها بمفرده سرية النظام.

    المُخرَج: سياسة الاحتفاظ لكل استجابة.

  3. 3

    فحص المفاتيح

    التحقق من طريقة العرض، وURI، والأبعاد التي تُغير التمثيل. يتعلق Vary بحقول الطلب؛ وليس بالتفويض. ابحث عن اللغة المحذوفة، وتفاوض التنسيق، وسياق الحساب في طبقات التطبيق.

    المُخرَج: المفاتيح واختبارات الفصل.

  4. 4

    إعادة التحقق والتغيير

    اختبار الاستجابات الجديدة والقديمة، وتحديثات البيانات، والحقوق الملغاة. فحص ETag، والتحقق الشرطي، وسلوك عدم توفر المصدر. قد تصبح الاستجابة الصحيحة سابقًا حساسة بعد الإلغاء.

    المُخرَج: سجلات ما قبل وما بعد.

  5. 5

    إعادة التشغيل باستخدام حسابين.

    استخدام هويات وعلامات وهمية. تبديل الطلبات لنفس عنوان URI باستخدام ذاكرات تخزين مؤقتة ساخنة وباردة. التحقق من تسجيل الخروج، والروابط المباشرة، والتسجيل دون تسجيل الرموز الحقيقية.

    المُخرَج: اختبارات سلبية واستراتيجية إبطال.

قياس حداثة الذاكرة المخبأة أيضاً

مثال افتراضي: البيانات لا تصف عميلاً أو نتيجة مرصودة.

الموقف

تتم قراءتان بسرعة، لكن إحداهما ما زالت تعرض إتاحة قديمة بعد تغير المصدر.

التحقق

قارن القيمة والإصدار وموضع القراءة والزمن منذ التغيير. اختبر الإبطال وانتهاء الصلاحية والوصول إلى المصدر وفق عقد النظام.

التصرف

حدد التقادم المقبول لكل استخدام وراقب الاختلافات. انخفاض زمن الاستجابة لا يثبت اتساق البيانات المقدمة.

ورقة عمل قابلة لإعادة الاستخدام

أكمل بملاحظاتك المعتمدة. هذه الحقول عبارة عن نموذج عمل، وليست نتائج مُلاحظة.

الحقلالمعلومات المطلوب تسجيلها
الاستجابةعام أو شخصي؛ الأبعاد
الطبقةذاكرة التخزين المؤقت، المالك والمفتاح
السياسةالاحتفاظ، التحديث والتحقق
التجربةسرد وهمي، التغيير والملاحظة

مثال عملي افتراضي

حالة توضيحية

مثال افتراضي: تعيد شبكة توصيل المحتوى (CDN) استخدام استجابة ملف تعريف على نفس عنوان URI لحسابين تجريبيين.

القرار والأدلة المتوقعة

يكشف السيناريو عن التسريب، ويفحص السياسة والمفاتيح، ثم يعيد تشغيله بعد التصحيح وإلغاء الوصول.

تمييز الآليات

الآليةالغرضالتحقق أو التقييد
منع التخزين المؤقتالسماح بالتخزين مع التحقق المطلوبلا يُفسر على أنه منع للتخزين
خاص غير مؤهلاستبعاد التخزين المؤقت المشتركلا يُفسر على أنه ضمان للسرية
منع التخزينمنع تخزين HTTP ذي الصلةفحص ذاكرة التخزين المؤقت للتطبيق وسجل التصفح بشكل منفصل

مؤشرات الإدارة

المؤشرما يقيسهالإجراء الأول
فصل الحساباتعدم وجود علامة من حساب آخرفحص المحتوى والروابط والبيانات الوصفية
التحقق من العمر والتقادمإعادة الاستخدام بما يتوافق مع السياسةاختبار انتهاء الصلاحية وعدم توفر المصدر
تأخير الإبطالالوقت حتى التمثيل المصححتسمية كل طبقة لا تزال قديمة

الأخطاء الشائعة

  • لا يُفسر على أنه منع للتخزين
  • لا يُفسر على أنه ضمان للسرية
  • فحص ذاكرة التخزين المؤقت للتطبيق وسجل التصفح بشكل منفصل

الأسئلة المتكررة

هل يعني عدم وجود ذاكرة تخزين مؤقت عدم الاحتفاظ بأي شيء؟

لا، يتطلب التحقق قبل إعادة الاستخدام؛ ولا يمنع التخزين كما يفعل منع التخزين.

هل يحمي Vary حقوق الوصول؟

لا. يشارك في اختيار التمثيل؛ وتبقى عملية التفويض منفصلة.

هل يجب تخزين كل واجهة برمجة تطبيقات مؤقتًا؟

لا. تعتمد الفوائد على التكلفة والحداثة والمخاطر. قد تبرر الاستجابات الحساسة تجنب استخدام ذاكرة التخزين المؤقت المشتركة.

ETag وتخزين HTTP المؤقت والتعديلات المتزامنة

الملاحظات المرجعية المفصّلة متاحة باللغة الإنجليزية في هذه النسخة.

ETag: revalidate responses and prevent lost updates

An ETag is an opaque validator for the selected representation. It compares versions; it is neither authorisation nor an access token, and it need not be a file hash. Personalised responses require separate decisions about access, cache selection and HTTP conditions.

Local teaching model: a representation already exists; at most one conditional field contains a single ETag or *. GET, HEAD and PUT are covered. Tag lists, date validators, ranges, creation, combined conditions and the already-succeeded modification exception are excluded. No network call, storage or state change occurs; this does not test your API.

مختبر شبكات تخيلي خالٍ من الأشخاص، وأجهزة على طاولة داكنة بإضاءة كهرمانية. رسم توضيحي تحريري مولّد بالذكاء الاصطناعي
Generated conceptual scene: a fictional empty network laboratory. It shows neither a real facility nor a protocol measurement.

Strong and weak ETag comparison serve different purposes

If-Match requires strong comparison: neither tag may start with W/. If-None-Match uses weak comparison, matching the opaque values regardless of W/. Values remain case-sensitive. The * wildcard checks representation existence here, not a particular version.

Strong and weak ETag comparison serve different purposes
Current tagReceived tagStrong comparisonWeak comparison
"v1""v1"MatchesMatches
"v1"W/"v1"Does not matchMatches
W/"v1"W/"v1"Does not matchMatches
"v1""v2"Does not matchDoes not match
"v1""V1"Does not matchDoes not match

Simulate an HTTP decision without contacting a server

The six parameters yield 432 combinations. Requiring a conditional field and selecting 204 for successful PUT are policies of this fictional scenario. Requiring any condition does not prevent every lost update: If-Match: * compares no version.

Model decision : 304

304: If-None-Match finds a weak match for GET or HEAD. Reuse the stored representation under cache rules with the revalidation metadata.

304 and 204: no response content.

Request excerpt

GET /demo/resource HTTP/1.1
Host: api.example.test
If-None-Match: W/"v1"

Response excerpt

HTTP/1.1 304 Not Modified
Date: Thu, 22 Oct 2026 00:00:00 GMT
ETag: "v1"
Cache-Control: private, no-cache

Fictional HTTP/1.1 excerpts for reading: bodies are omitted even where allowed. api.example.test is an example domain. The date is fixed. This model does not update the ETag after PUT; the separate walkthrough follows successive versions.

Ten reproducible situations

Ten reproducible situations
Fictional situationCondition and expected outcomeInterpretation
Read using a weak tagGET · "v1"
If-None-Match: W/"v1" → 304

Access allowed · Conditional field optional

W/"v1" and "v1" match weakly.
Different client versionGET · "v1"
If-None-Match: "v2" → 200

Access allowed · Conditional field optional

The client needs the selected representation.
HEAD revalidationHEAD · "v1"
If-None-Match: "v1" → 304

Access allowed · Conditional field optional

The status can be 304; the response has no content.
Write based on an old versionPUT · "v2"
If-Match: "v1" → 412

Access allowed · Conditional field optional

Read again and resolve the conflict before retrying.
Weak tag with If-MatchPUT · "v1"
If-Match: W/"v1" → 412

Access allowed · Conditional field optional

Strong comparison rejects a weak tag.
Required condition absent on PUTPUT · "v1"
none → 428

Access allowed · Conditional field required

428 follows the policy announced by this API.
Access denied despite matching tagGET · "v1"
If-None-Match: "v1" → 403

Access denied · Conditional field optional

Authorisation precedes HTTP conditions.
Write on the correct versionPUT · "v1"
If-Match: "v1" → 204

Access allowed · Conditional field required

The model accepts PUT and selects a 204 success.
If-None-Match: * on existing dataPUT · "v1"
If-None-Match: * → 412

Access allowed · Conditional field optional

The wildcard matches any existing representation.
If-Match: * on existing dataPUT · W/"v1"
If-Match: * → 204

Access allowed · Conditional field required

The wildcard passes even with a weak current tag: it does not protect a version.

Four rules for a personalised response

Four rules for a personalised response
Response fieldHTTP effect within this scopeEvidence to retain
Cache-Control: no-cacheUnqualified no-cache permits storage, but any reuse needs successful validation with the origin server.Observe a conditional round trip; do not read no-cache as a storage prohibition.
Cache-Control: no-storeForbids storage by private and shared HTTP caches. It is not a general privacy guarantee.Also review logs, history, screenshots and application storage.
Cache-Control: privateUnqualified private forbids storage by a shared cache; a private cache may store under the other constraints.Distinguish browser, proxy and CDN. A directive does not replace access checks.
VaryAdds the named request fields to selection of a stored response. It does not decide who may access a resource.Test relevant variants. Do not assume a cookie or Authorization automatically prevents all caching.

Useful API acceptance evidence

  • Expected request and status: method, test resource, access rights, conditional field and current ETag. Use fictional data and remove secrets.
  • Observed response: status, ETag, Date, Cache-Control, Vary and no content for HEAD, 204 or 304. A 304 must carry the required metadata that would have accompanied the 200.
  • Concurrency: verify that a stale write fails without changing the resource; retain the conflict-resolution decision. Do not blindly replace the ETag and resend the same write.

Follow the two-client conflict →

Primary references and limits

The standards define HTTP conditions and caching. The ten cases, laboratory and two-client walkthrough are original illustrations. Displayed results are calculated by this local model, not measurements of this site or your infrastructure.

References reviewed

المراجع الرسمية

تدعم المراجع الطريقة. قم بتكييف عمليات التحقق مع سياقك؛ فهي ليست شهادة. قد تكون عناوين المراجع الأصلية والوثائق المصدرية بلغة أخرى.

تاريخ مراجعة المراجع .