| Server IP : 217.160.0.135 / Your IP : 216.73.217.85 Web Server : Apache System : Linux www 6.18.52-i1-ampere #1203 SMP Mon Sep 14 18:29:59 CEST 2026 aarch64 User : sws1074145052 ( 1074145052) PHP Version : 8.3.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /lib/python3/dist-packages/django/middleware/__pycache__/ |
Upload File : |
�
�|�e# � � � d Z ddlmZ ddlmZmZ ddlmZmZm Z m
Z
mZ ddlm
Z
G d� de
� � Z G d� d e
� � Z G d
� dee� � ZdS )
a�
Cache middleware. If enabled, each Django-powered page will be cached based on
URL. The canonical way to enable cache middleware is to set
``UpdateCacheMiddleware`` as your first piece of middleware, and
``FetchFromCacheMiddleware`` as the last::
MIDDLEWARE = [
'django.middleware.cache.UpdateCacheMiddleware',
...
'django.middleware.cache.FetchFromCacheMiddleware'
]
This is counter-intuitive, but correct: ``UpdateCacheMiddleware`` needs to run
last during the response phase, which processes middleware bottom-up;
``FetchFromCacheMiddleware`` needs to run last during the request phase, which
processes middleware top-down.
The single-class ``CacheMiddleware`` can be used for some simple sites.
However, if any other piece of middleware needs to affect the cache key, you'll
need to use the two-part ``UpdateCacheMiddleware`` and
``FetchFromCacheMiddleware``. This'll most often happen when you're using
Django's ``LocaleMiddleware``.
More details about how the caching works:
* Only GET or HEAD-requests with status code 200 are cached.
* The number of seconds each page is stored for is set by the "max-age" section
of the response's "Cache-Control" header, falling back to the
CACHE_MIDDLEWARE_SECONDS setting if the section was not found.
* This middleware expects that a HEAD request is answered with the same response
headers exactly like the corresponding GET request.
* When a hit occurs, a shallow copy of the original response object is returned
from process_request.
* Pages will be cached based on the contents of the request headers listed in
the response's "Vary" header.
* This middleware also sets ETag, Last-Modified, Expires and Cache-Control
headers on the response object.
� )�settings)�DEFAULT_CACHE_ALIAS�caches)�
get_cache_key�get_max_age�has_vary_header�learn_cache_key�patch_response_headers)�MiddlewareMixinc �0 � � e Zd ZdZd� fd� Zd� Zd� Z� xZS )�UpdateCacheMiddlewarea6
Response-phase cache middleware that updates the cache if the response is
cacheable.
Must be used as part of the two-part update/fetch cache middleware.
UpdateCacheMiddleware must be the first piece of middleware in MIDDLEWARE
so that it'll get called last during the response phase.
Nc �� �� t � � � |� � t j | _ d | _ t j | _ t j | _ t | j | _ d S �N)�super�__init__r �CACHE_MIDDLEWARE_SECONDS�
cache_timeout�page_timeout�CACHE_MIDDLEWARE_KEY_PREFIX�
key_prefix�CACHE_MIDDLEWARE_ALIAS�cache_aliasr �cache��self�get_response� __class__s ��9/usr/lib/python3/dist-packages/django/middleware/cache.pyr zUpdateCacheMiddleware.__init__B sV �� �
������&�&�&�%�>��� ���"�>���#�:����D�,�-��
�
�
� c �0 � t |d� � o|j S )N�_cache_update_cache)�hasattrr! )r �request�responses r �_should_update_cachez*UpdateCacheMiddleware._should_update_cacheJ s � ��w� 5�6�6�V�7�;V�Vr c �T � ��� � � ||� � s|S |j s |j dvr|S |j s|j rt |d� � r|S d|� dd� � v r|S � j ���!t |� � ���� j �n�dk r|S t |�� � �r�|j dk ryt ||�� j � j
� � � �t |d
� � r/t |j � � r|� �� �fd�� � n� j
� �|�� � |S )zSet the cache, if needed.)�� i0 �Cookie�privatez
Cache-Control� Nr r'