0Pricing
Django Academy · درس

التخزين المؤقت لأجزاء القوالب

تخزين الأجزاء المكلفة من الصفحة مؤقتًا فقط

التخزين المؤقت لأجزاء القوالب درس مجاني في Django Academy على CoddyKit. هذا هو الدرس 3 من أصل 4. يمكنك قراءة الدرس كاملاً أدناه مجاناً — ثم تمرن عليه مباشرة في المتصفح باستخدام محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7. هذا الدرس جزء من مسار التعلم في Django Academy، وتقدمك يتزامن عبر الويب وتطبيق CoddyKit. تتضمن دورة Django Academy 4 دروس في المجموع.

بعض أجزاء هذا الدرس لم تُترجم بعد وتظهر باللغة الإنجليزية.

Cache Just One Piece

Often only part of a page is slow. Fragment caching lets you cache that one block while the rest renders fresh each time.

Load the cache Tag

Fragment caching lives in a template tag library, so start your template with load cache to make it available.

{% load cache %}

The cache Block

Wrap the slow markup in a cache block. Django renders it once, stores the HTML, and reuses it on later requests.

{% cache 500 sidebar %}
  ...expensive sidebar...
{% endcache %}

Timeout Comes First

The first argument is the timeout in seconds. After it expires, the next render rebuilds the fragment and caches it again.

Name Your Fragment

The second argument is a fragment name. Django combines it with extra arguments to form the unique cache key.

Vary the Fragment

Add variables after the name so a fragment can vary per user or object, caching one copy for each distinct value.

{% cache 500 sidebar request.user.id %}
  ...per-user sidebar...
{% endcache %}

Each Variation Is Separate

Every combination of the vary arguments gets its own key, so user 1 and user 2 each see their own cached copy.

Use a Specific Cache

Point a fragment at a named cache with using when you keep page fragments separate from other cached data.

{% cache 500 sidebar using="fragments" %}

Great for Shared Widgets

Fragment caching shines for shared widgets like a navbar or a top-posts list that look the same for many visitors.

Keep Live Parts Outside

Leave anything that must stay current, like a greeting with the user's name, outside the cache block so it never goes stale.

Less Effort Than View Caching

Fragment caching is the middle ground: more precise than caching a whole view, yet far simpler than caching every query by hand.

Quick Check

Let's check how a fragment stays unique per user.

Recap

You can now load cache, wrap a fragment in a cache block with a timeout and name, and vary it per user for precise speedups. ✨

الأسئلة الشائعة

هل درس «التخزين المؤقت لأجزاء القوالب» مجاني؟

نعم — نص درس «التخزين المؤقت لأجزاء القوالب» كامل متاح مجاناً هنا على الويب. لتمرينه بشكل تفاعلي (محرر أكواد مدمج ومدرس ذكاء اصطناعي متاح 24/7) وفتح باقي دورة Django Academy، انتقل إلى CoddyKit PRO. تتضمن دورة Django Academy 4 دروس في المجموع.

ماذا ستتعلم في «التخزين المؤقت لأجزاء القوالب»؟

تخزين الأجزاء المكلفة من الصفحة مؤقتًا فقط تتمرن على Django Academy مع أكواد عملية تشغلها مباشرة في المتصفح، ومدرس ذكاء اصطناعي متاح 24/7 يجيب على أسئلتك أثناء عملك.

هل أحتاج إلى خبرة سابقة لأبدأ Django Academy؟

لا تُشترط خبرة سابقة. Django Academy على CoddyKit منظم للمبتدئين حتى المتقدمين، لذا يمكنك البدء من هنا أو من البداية والتقدم بسرعتك الخاصة. هذا هو الدرس 3 من أصل 4.

كم من الوقت يستغرق درس «التخزين المؤقت لأجزاء القوالب»؟

معظم دروس CoddyKit تستغرق حوالي 5–10 دقائق. كل منها موجز وتفاعلي، لذا تحرز تقدماً مستمراً وتستأنف من حيث توقفت عبر الويب والتطبيق.

هل يمكنني كتابة وتشغيل أكواد في درس Django Academy هذا؟

نعم. كل درس في Django Academy يتضمن محرر أكواد مدمج، لذا تكتب وتشغل أكواداً حقيقية مباشرة في متصفحك وتحصل على تعليقات فورية من الذكاء الاصطناعي — بدون إعداد محلي.

جميع الدروس في هذه الدورة

  1. واجهات تخزين Cache وRedis
  2. التخزين المؤقت لكل عرض ولكل موقع
  3. التخزين المؤقت لأجزاء القوالب
  4. واجهة Cache منخفضة المستوى وإبطالها
← العودة إلى Django Academy