عرض عملي: تخزين تفاصيل المنتج مؤقتًا باستخدام @Cacheable
في هذا الدرس 3 موضوعات
هذا الدرس مخطط له. يعرض المخطط أدناه الموضوعات التي سيغطيها، ولم يُنشر الدرس الكامل بعد.
نص الدروس والتمارين باللغة الإنجليزية، بينما تبقى واجهة الموقع وعناوين الدروس بالعربية.
في هذا الدرس
cache product details in Redis with a TTL and metrics. Prepares MID-038-LAB1.
تفاصيل المخطط المبدئي
خطوة بخطوة
- Add the Redis starter and a
RedisCacheManagerwith a 10-minute TTL forproducts. - Annotate
findProductwith@Cacheableand the update method with@CacheEvict. - Enable cache statistics and read hits/misses in Micrometer (verify the metric names for your Spring Boot version).
- Run a load test; compare latency with and without the cache.
- Planned mistake: cache a
Productentity that is notSerializableand uses Java serialization; it fails or breaks on a class change. Fix: cache a small DTO with JSON serialization. - Show the keys with
SCAN 0 MATCH products::*.
اختبر فهمك
Which operation removes a stale product when its price changes?
أظهر الإجابة
@CacheEvict, or event-based invalidation in MID-039.
التطبيق
طبّق هذا الدرس بمختبر الوحدة وتمارينها واختبارها.
تعليم الدرس كمكتمل اختياري ويمكنك التراجع عنه في أي وقت. يبقى تقدمك محفوظًا في هذا المتصفح.