انتقل إلى المحتوى
أمين أبوزيد
MID-039

أنماط التخزين المؤقت

  • 5 درس
  • 2.5 ساعة تدريب (تقدير)
في هذه الصفحة 8 موضوعات

نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.

نظرة عامة

الموضوعات

  • Cache-aside
  • write-through
  • write-behind
  • الإبطال (Invalidation)

تعلّم أولًا

2.5 ساعة تدريب (تقدير)

مخرجات التعلم

  1. Implement cache-aside, read-through, write-through, and write-behind, and state each one's failure behavior.
  2. Invalidate on change via events instead of relying on TTL alone.
  3. Explain the risk of write-behind and when it is acceptable.

الدروس

  1. 01Cache-aside
  2. 02Read-through وwrite-through
  3. 03Write-behind
  4. 04استراتيجيات الإبطال
  5. 05عرض عملي: إبطال موجّه بالأحداث من ProductUpdated

المختبر والتمارين

Lab

MID-039-LAB1 · Fresh catalog

Outcomes: 1–3 · Time: ~2.5 h Implement cache-aside for product reads. When the catalog service publishes ProductUpdated, the cache consumer evicts the key. Keep a TTL as safety net. Measure the delay between a price change and the new price being visible. Acceptance: price change visible within one second.

Exercises (assessment: pattern-choice scenarios)

IDOutcomeTask
MID-039-EX011Write a cache-aside getProduct and updateProduct and state what happens if Redis is down.
MID-039-EX021Compare read-through and write-through: who calls the database in each, and what fails when the database is slow?
MID-039-EX033Decide whether write-behind is acceptable for: page-view counts, orders, user profile edits. Justify.
MID-039-EX042Choose an invalidation strategy for product price, category names, and the home-page banner.
MID-039-EX051Explain what goes wrong with "update the cache, then the database" if the database write fails.
أظهر الحلول
  • EX01 See L01 code. Redis down: reads go to the database (slower, correct); writes still succeed; wrap cache calls so cache errors do not fail the request.
  • EX02 Read-through: cache layer loads on miss. Write-through: cache layer writes to the database synchronously. Slow database makes cache misses and writes slow too.
  • EX03 Page views: yes (loss tolerable). Orders: no. Profile edits: no, users expect saved data.
  • EX04 Price: event-driven eviction plus a short TTL. Category names: TTL of an hour is fine. Banner: TTL or delete on admin change.
  • EX05 The cache holds a value that was never stored: readers see data that does not exist. Write the database first, then delete the cache entry.

Outcome 2 is also covered by the lab criterion (price visible within one second).

الاختبار

Outcomes: O1 the four patterns and their failures · O2 invalidation by events · O3 write-behind risk.

اختبار ذاتي لك: لا توجد درجات، ولا يُحفظ أو يُرسل أي شيء. اختر إجابة ثم تحقق منها، ويمكنك المحاولة مرة أخرى كما تشاء.

  1. 1In cache-aside, on a miss the:O1
  2. 2On a write in cache-aside, the usual order is:O1
  3. 3If the cache is down in cache-aside:O1
  4. 4Write-through means:O1
  5. 5Read-through differs from cache-aside because:O1
  6. 6Best way to keep prices fresh across services:O2
  7. 7Why still use a TTL with events?O2
  8. 8Why delete rather than update the entry on change?O2
  9. 9Main risk of write-behind:O3
  10. 10Where is write-behind acceptable?O3

الجزء العملي

Pattern-choice scenarios (MID-039-EX03, EX04) plus lab MID-039-LAB1. Pass: quiz at least 8/10, correct patterns in the scenarios, and a lab where a price change is visible within one second.

أخطاء شائعة

Updating cache and database in the wrong order; relying on TTL for prices.

التقييم

Pattern-choice scenarios.

الصلة بالمسار الوظيفي

Cache consistency (MID-040).

اكتب للبحث في المستويات والمراحل والوحدات والدروس.