
    j$                         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Jr  SSKJr  SSKJrJr   " S S	\5      r " S
 S\5      r " S S\\5      rg)ai  
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.

* If the request had an Authorization header and the response was not marked
  "Cache-Control: public", the response will vary on Authorization.
    N)settings)DEFAULT_CACHE_ALIAScaches)get_cache_keyget_max_agehas_vary_headerlearn_cache_keypatch_response_headerspatch_vary_headers)MiddlewareMixin)parse_http_date_safesplit_directive_namesc                   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     O/var/www/html/KUNJ/venv/lib/python3.13/site-packages/django/middleware/cache.pyr   UpdateCacheMiddleware.__init__J   sA    &%>> ">>#::    c                 (    [         U R                     $ r   r   r   r   s    r!   cacheUpdateCacheMiddleware.cacheQ       d&&''r#   c                 @    [        US5      =(       a    UR                  $ )N_cache_update_cache)hasattrr+   )r   requestresponses      r!   _should_update_cache*UpdateCacheMiddleware._should_update_cacheU   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                  (       a  [	        US5      (       a  U$ [        [        UR                  SS5      5      5      nUR                  1 Sk5      (       a  U$ [	        U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        UR                  R                  S5      (       a  S	U;  a  [        US
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  CookiezCache-Control >   privateno-cacheno-store*r   Authorizationpublic)r9   r2   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cookiesr   r>   r   getintersectionr   r   r   r
   headersr   r	   r   r'   r,   callabler<   add_post_render_callback)r   r-   r.   cache_control_partsr@   rA   s   `   @@r!   process_response&UpdateCacheMiddleware.process_responseX   s   ((;;O!5!5Z!GO ( C CO
 "!(,,"CD
 ++,OPPO 8S))O ##? "(+G,,Ax1
 ??//HDW4Wx);<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/   rM   __static_attributes____classcell__r    s   @r!   r   r   @   s1    ; ( (W8 8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HEADFNra   r;   Trb   Expiresr   Age)methodr+   r   r   r'   rG   r   r   inttimemax)r   r-   r@   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   )rP   rQ   rR   rS   rT   r   rU   r'   rm   rV   rW   rX   s   @r!   rZ   rZ      s+    ;
 ( (& &r#   rZ   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   r4   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$rO   )NN)rP   rQ   rR   rS   rT   r   rV   rW   rX   s   @r!   rp   rp      s    ) )r#   rp   )rT   rg   django.confr   django.core.cacher   r   django.utils.cacher   r   r   r	   r
   r   django.utils.deprecationr   django.utils.httpr   r   r   rZ   rp    r#   r!   <module>r|      sT   -^    9  5 IPO Pf8 8v )+-E  )r#   