3๐
You cache fragments of a template using the {% cache %}
template tag:
{% load cache %} <-- at the top of the template
{% cache 500 sidebar %}
.. sidebar ..
{% endcache %}
It takes at least two arguments: the cache timeout, in seconds, and
the name to give the cache fragment.
3๐
TD;DR
HTML templates are compiled and cached in memory. Modifying the original HTML template files will not purge existing cached templates. One way to reset the cache is to restart the uwsgi/gunicorn service.
How template cache works?
Considring the following Django settings (https://docs.djangoproject.com/en/2.2/ref/settings/), OPTIONS['loaders']
isnโt specified and OPTIONS['debug']
is False
(defaults to the value of DEBUG
).
DEBUG = False
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
django.template.loaders.cached.Loader is then automatically enabled. The cached loader then stores the compiled Template
in memory after unknown templates are first encountered. These compiled templates are stored in a dict named get_template_cache
(though the variable name sounds like a method).
- [Django]-How to configure django to generate signed urls for media files with Google Cloud CDN?
- [Django]-MongoDB storage along with MySQL XPath features
0๐
for css
and js
files you can use django-compressor
that can compress files and every time developer change js
or css
codes, just run manage.py compress
on server and automatic generate new files that has uuid at end of files name and remove last files
for other part for other parts of page do as doru said
- [Django]-Serving many on-the-fly generated images with Django
- [Django]-Django โ Slugify get lookup