Ë
    q^ëi  ã                   ó�   — d Z ddlmZ ddlmZmZ ddlmZmZm	Z	m
Z
mZ ddlmZ  G d„ de«      Z G d„ d	e«      Z G d
„ dee«      Zy)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                   ó>   ‡ — e Zd ZdZˆ fd„Zed„ «       Zd„ Zd„ Zˆ xZ	S )Ú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.
    c                 ó°   •— t         ‰| �  |«       t        j                  | _        d | _        t        j                  | _        t        j                  | _	        y ©N)
ÚsuperÚ__init__r   ÚCACHE_MIDDLEWARE_SECONDSÚcache_timeoutÚpage_timeoutÚCACHE_MIDDLEWARE_KEY_PREFIXÚ
key_prefixÚCACHE_MIDDLEWARE_ALIASÚcache_alias©ÚselfÚget_responseÚ	__class__s     €úH/var/www/eb/venv/lib/python3.12/site-packages/django/middleware/cache.pyr   zUpdateCacheMiddleware.__init__D   sA   ø€ Ü‰Ñ˜Ô&Ü%×>Ñ>ˆÔØ ˆÔÜ"×>Ñ>ˆŒÜ#×:Ñ:ˆÕó    c                 ó(   — t         | j                     S r   ©r   r   ©r   s    r   ÚcachezUpdateCacheMiddleware.cacheK   ó   € ä�d×&Ñ&Ñ'Ð'r   c                 ó6   — t        |d«      xr |j                  S )NÚ_cache_update_cache)Úhasattrr%   )r   ÚrequestÚresponses      r   Ú_should_update_cachez*UpdateCacheMiddleware._should_update_cacheO   s   € Ü�wÐ 5Ó6ÒV¸7×;VÑ;VÐVr   c                 óp  ‡ ‡‡— ‰ j                  ||«      s|S |j                  s|j                  dvr|S |j                  s|j                  rt        |d«      r|S d|j                  dd«      v r|S ‰ j                  Š‰€!t        |«      Š‰€‰ j                  Šn‰dk(  r|S t        |‰«       ‰r‰|j                  dk(  rzt        ||‰‰ j                  ‰ j                  ¬«      Št        |d	«      r-t        |j                   «      r|j#                  ˆˆ ˆfd
„«       |S ‰ j                  j%                  ‰|‰«       |S )zSet the cache, if needed.)éÈ   i0  ÚCookieÚprivatezCache-Control© r   r+   ©r"   Úrenderc                 ó>   •— ‰j                   j                  ‰| ‰«      S r   )r"   Úset)ÚrÚ	cache_keyr   Útimeouts    €€€r   ú<lambda>z8UpdateCacheMiddleware.process_response.<locals>.<lambda>{   s   ø€ ˜dŸj™jŸn™n¨Y¸¸7ÓC€ r   )r)   Ú	streamingÚstatus_codeÚCOOKIESÚcookiesr   Úgetr   r   r   r
   r	   r   r"   r&   Úcallabler0   Úadd_post_render_callbackr2   )r   r'   r(   r4   r5   s   `  @@r   Úprocess_responsez&UpdateCacheMiddleware.process_responseR   s)  ú€ à×(Ñ(¨°(Ô;àˆOà×Ò ×!5Ñ!5¸ZÑ!GØˆOð
 —’Ø× Ò Ü ¨(Ô3àˆOð ˜Ÿ™ _°bÓ9Ñ9ØˆOð ×#Ñ#ˆØˆ?ô " (Ó+ˆGØˆØ×,Ñ,‘Ø˜A’à�Ü˜x¨Ô1Ù�x×+Ñ+¨sÒ2Ü'Ø˜ 7¨D¯O©OÀ4Ç:Á:ôˆIô �x Ô*¬x¸¿¹Ô/HØ×1Ñ1ÝCôð
 ˆð —
‘
—‘˜y¨(°GÔ<Øˆr   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr"   r)   r>   Ú__classcell__©r   s   @r   r   r   :   s,   ø„ ñô;ð ñ(ó ð(òWö-r   r   c                   ó8   ‡ — e Zd ZdZˆ fd„Zed„ «       Zd„ Zˆ xZS )ÚFetchFromCacheMiddlewarea!  
    Request-phase cache middleware that fetches a page from the cache.

    Must be used as part of the two-part update/fetch cache middleware.
    FetchFromCacheMiddleware must be the last piece of middleware in MIDDLEWARE
    so that it'll get called last during the request phase.
    c                 óx   •— t         ‰| �  |«       t        j                  | _        t        j
                  | _        y r   )r   r   r   r   r   r   r   r   s     €r   r   z!FetchFromCacheMiddleware.__init__‹   s+   ø€ Ü‰Ñ˜Ô&Ü"×>Ñ>ˆŒÜ#×:Ñ:ˆÕr   c                 ó(   — t         | j                     S r   r    r!   s    r   r"   zFetchFromCacheMiddleware.cache�   r#   r   c                 ó‚  — |j                   dvrd|_        yt        || j                  d| j                  ¬«      }|€d|_        y| j                  j                  |«      }|€M|j                   dk(  r>t        || j                  d| j                  ¬«      }| j                  j                  |«      }|€d|_        yd|_        |S )zn
        Check whether the page is already cached and return the cached
        version if available.
        )ÚGETÚHEADFNrK   r/   TrL   )Úmethodr%   r   r   r"   r;   )r   r'   r4   r(   s       r   Úprocess_requestz(FetchFromCacheMiddleware.process_request”   s¸   € ð
 �>‰> Ñ0Ø*/ˆGÔ'Øô " '¨4¯?©?¸EÈÏÉÔTˆ	ØÐØ*.ˆGÔ'ØØ—:‘:—>‘> )Ó,ˆàÐ §¡°&Ò 8Ü%Ø˜Ÿ™¨&¸¿
¹
ôˆIð —z‘z—~‘~ iÓ0ˆHàÐØ*.ˆGÔ'Øð ',ˆÔ#Øˆr   )	r?   r@   rA   rB   r   rC   r"   rN   rD   rE   s   @r   rG   rG   ‚   s&   ø„ ñô;ð
 ñ(ó ð(ör   rG   c                   ó$   ‡ — e Zd ZdZdˆ fd„	Zˆ xZS )ÚCacheMiddlewarezÌ
    Cache middleware that provides basic behavior for many simple sites.

    Also used as the hook point for the cache decorator, which is generated
    using the decorator-from-middleware utility.
    c                 óÌ   •— t         ‰| �  |«       	 |d   }|€d}|| _        	 |d   }|€t        }|| _        |�|| _        || _        y # t        $ r Y Œ1w xY w# t        $ r Y Œ+w xY w)Nr   Ú r   )r   r   r   ÚKeyErrorr   r   r   r   )r   r   r   r   Úkwargsr   r   r   s          €r   r   zCacheMiddleware.__init__»   s’   ø€ Ü‰Ñ˜Ô&ð	Ø Ñ-ˆJØÐ!Ø�
Ø(ˆDŒOð	Ø  Ñ/ˆKØÐ"Ü1�Ø*ˆDÔð Ð$Ø!.ˆDÔØ(ˆÕøô ò 	Ùð	ûô ò 	Ùð	ús"   ’A £A Á	AÁAÁ	A#Á"A#)NN)r?   r@   rA   rB   r   rD   rE   s   @r   rP   rP   ³   s   ø„ ñ÷)ñ )r   rP   N)rB   Údjango.confr   Údjango.core.cacher   r   Údjango.utils.cacher   r   r   r	   r
   Údjango.utils.deprecationr   r   rG   rP   r.   r   r   ú<module>rY      sN   ðñ+õZ !ß 9÷õ õ 5ôE˜Oô EôP.˜ô .ôb )Ð+Ð-Eõ  )r   