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

عرض عملي: ذاكرة Caffeine مؤقتة محلية مع مقاييس

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

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

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

في هذا الدرس

add a Caffeine cache to a Shop endpoint and read its stats. Prepares MID-037-LAB1.

تفاصيل المخطط المبدئي

خطوة بخطوة

  1. Add the Caffeine dependency and build a Cache<Long, ProductDto> with maximumSize(1000), expireAfterWrite(5, MINUTES), and recordStats().
  2. Wrap findProduct(id): cache.get(id, this::loadFromDb).
  3. Expose cache.stats() through Micrometer (hit count, miss count, load time).
  4. Generate load with a small script; show the hit ratio rising after warm-up.
  5. Planned mistake: cache the per-customer discounted price by product id only; a second customer sees the first customer's price. Fix: cache the shared base price and apply the discount afterwards, or include the customer tier in the key.
  6. Verify Caffeine version and Micrometer binding names before recording.

اختبر فهمك

Why is recordStats() needed?

أظهر الإجابة

Without it the cache reports no hit or miss counts.

التطبيق

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

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

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

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