
    h'!                         S r SSKrSSKJr  SSKJrJr  SSKJrJ	r	J
r
JrJr  SSKJr  SSKJr   " S S	\5      r " S
 S\5      r " S S\\5      rg)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 counterintuitive, 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.

    N)settings)DEFAULT_CACHE_ALIAScaches)get_cache_keyget_max_agehas_vary_headerlearn_cache_keypatch_response_headers)MiddlewareMixin)parse_http_date_safec                   H   ^  \ rS rSrSrU 4S jr\S 5       rS rS r	Sr
U =r$ )UpdateCacheMiddleware=   a  
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U ]  U5        [        R                  U l        S U l        [        R                  U l        [        R                  U l	        g 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     I/var/www/html/env/lib/python3.13/site-packages/django/middleware/cache.pyr   UpdateCacheMiddleware.__init__G   sA    &%>> ">>#::    c                 (    [         U R                     $ r   r   r   r   s    r   cacheUpdateCacheMiddleware.cacheN       d&&''r!   c                 @    [        US5      =(       a    UR                  $ )N_cache_update_cache)hasattrr)   )r   requestresponses      r   _should_update_cache*UpdateCacheMiddleware._should_update_cacheR   s    w 56V7;V;VVr!   c                   ^ ^^ T R                  X5      (       d  U$ UR                  (       d  UR                  S;  a  U$ UR                  (       d$  UR                  (       a  [        US5      (       a  U$ SUR                  SS5      ;   a  U$ T R                  mTc#  [        U5      mTc  T R                  mOTS:X  a  U$ [        UT5        T(       a  UR                  S:X  a  [        XTT R                  T R                  S9m[        US	5      (       a3  [        UR                   5      (       a  UR#                  UU U4S
 j5        U$ T R                  R%                  TUT5        U$ )zSet the cache, if needed.)   i0  CookieprivatezCache-Control r   r0   r%   renderc                 >   > TR                   R                  TU T5      $ r   )r%   set)r	cache_keyr   timeouts    r   <lambda>8UpdateCacheMiddleware.process_response.<locals>.<lambda>~   s    djjnnY7Cr!   )r-   	streamingstatus_codeCOOKIEScookiesr   getr   r   r   r
   r	   r   r%   r*   callabler5   add_post_render_callbackr7   )r   r+   r,   r9   r:   s   `  @@r   process_response&UpdateCacheMiddleware.process_responseU   s1   ((;;O!5!5Z!GO
   (33O _b99O ##? "(+G,,Ax1x++s2'7DOO4::I x**x/H/H11C
  

y(G<r!   r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   propertyr%   r-   rD   __static_attributes____classcell__r   s   @r   r   r   =   s1    ; ( (W- -r!   r   c                   B   ^  \ rS rSrSrU 4S jr\S 5       rS rSr	U =r
$ )FetchFromCacheMiddleware   a  
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U ]  U5        [        R                  U l        [        R
                  U l        g r   )r   r   r   r   r   r   r   r   s     r   r   !FetchFromCacheMiddleware.__init__   s+    &">>#::r!   c                 (    [         U R                     $ r   r#   r$   s    r   r%   FetchFromCacheMiddleware.cache   r'   r!   c                 $   UR                   S;  a  SUl        g[        XR                  SU R                  S9nUc  SUl        gU R                  R                  U5      nUcJ  UR                   S:X  a:  [        XR                  SU R                  S9nU R                  R                  U5      nUc  SUl        g[        U5      =nbE  [        US   5      =n b3  [        [        R                  " 5       5      nXV-
  n[        S	XG-
  5      US
'   SUl        U$ )zV
Check whether the page is already cached and return the cached
version if available.
)GETHEADFNrX   r4   TrY   Expiresr   Age)methodr)   r   r   r%   rA   r   r   inttimemax)r   r+   r9   r,   max_age_secondsexpires_timestampnow_timestampremaining_secondss           r   process_request(FetchFromCacheMiddleware.process_request   s   
 >>0*/G' "'??ET	*.G'::>>),& 8%&

I zz~~i0H*.G'  +844OA!5hy6I!JJG  		,M 1 A!!_%HIHUO ',#r!   )r   r   )rG   rH   rI   rJ   rK   r   rL   r%   rd   rM   rN   rO   s   @r   rQ   rQ      s+    ;
 ( (% %r!   rQ   c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )CacheMiddleware   z
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U ]  U5         US   nUc  SnXPl         US   nUc  [        nX`l        Ub  X l        X0l        g ! [         a     N1f = f! [         a     N,f = f)Nr    r   )r   r   r   KeyErrorr   r   r   r   )r   r   r   r   kwargsr   r   r   s          r   r   CacheMiddleware.__init__   s    &	-J!
(O	 /K"1* $!.(  		  		s"   A A 
AA
A$#A$rF   )NN)rG   rH   rI   rJ   rK   r   rM   rN   rO   s   @r   rg   rg      s    ) )r!   rg   )rK   r^   django.confr   django.core.cacher   r   django.utils.cacher   r   r   r	   r
   django.utils.deprecationr   django.utils.httpr   r   rQ   rg   r3   r!   r   <module>rs      sT   +Z    9  5 2EO EP7 7t )+-E  )r!   