انتقل إلى المحتوى
أمين أبوزيد
درس مخطط لهMID-039-L01

Cache-aside

  • الدرس 1 من 5
  • Mid-level
في هذا الدرس 4 موضوعات

هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.

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

في هذا الدرس

implement the most common pattern and know how it fails.

الموضوعات المخطط لها

  • The application owns the logic: read the cache; on a miss read the database, then fill the cache.
  • On write: update the database first, then delete (not update) the cache entry.
  • Failure: if the cache is down, reads fall through to the database (slower, still correct). If the delete fails, stale data stays until TTL.
  • Simple and robust; the cost is repeated code and a miss penalty on first read.
تفاصيل المخطط المبدئي

عرض عملي

java
ProductDto get(long id) {
    var hit = cache.get(key(id));
    if (hit != null) return hit;
    var p = repo.load(id);
    cache.put(key(id), p, ttl);
    return p;
}
void update(Product p) { repo.save(p); cache.delete(key(p.id())); }

اختبر فهمك

On a write, which first: database or cache delete?

أظهر الإجابة

Database, then delete the cache entry.

التطبيق

طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.

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

تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.

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