
    Vpf                        U d dl mZ d dlZd dlZd dlZd dlmZ d dlZdZde	d<   	 d dlZn# e
$ r Y nw xY wd dlmZ d dlmZ  ej        e          ZdZd	ZddZ G d de          ZdS )    )annotationsN)Anyz
Any | Nonefilelockpath)CacheInterfacez-cachez-atimer   strreturnboolc                4    |                      d          pd| vS )Nzfile://z://)
startswithr   s    R/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/jax/_src/lru_cache.py_is_local_filesystemr   '   s    		#	#	8uD'88    c                  >    e Zd ZdZdddd
ZddZddZddddZdS )LRUCachea;  Bounded cache with least-recently-used (LRU) eviction policy.

  This implementation includes cache reading, writing and eviction
  based on the LRU policy.

  Notably, when ``max_size`` is set to -1, the cache eviction
  is disabled, and the LRU cache functions as a normal cache
  without any size limitations.
  
   )lock_timeout_secsr   r	   max_sizeintr   float | Nonec                  t          |          st          j        st          d          t          j        |          x| _        | _        | j                            dd           |dk    | _        | j        rt          t          d          || _
        || _        | j        dz  | _        t          |          r t          j        | j                  | _        dS t          j        | j                  | _        dS dS )a_  Args:

      path: The path to the cache directory.
      max_size: The maximum size of the cache in bytes. Caching will be
        disabled if this value is set to ``0``. A special value of ``-1``
        indicates no limit, allowing the cache size to grow indefinitely.
      lock_timeout_secs: (optional) The timeout for acquiring a file lock.
    z`Please install the `etils[epath]` package to specify a cache directory on a non-local filesystemT)parentsexist_okNzMPlease install the `filelock` package to set `jax_compilation_cache_max_size`z	.lockfile)r   pathlibepath_installedRuntimeErrorPathr   _pathmkdireviction_enabledr   r   r   	lock_pathFileLocklockSoftFileLock)selfr   r   r   s       r   __init__zLRUCache.__init__6   s      %% }g.E }{|||$\$///DI
IOOD4O000$ND :		jkkkdm0dy;.dn	d	#	# :%dn55			)$.99			: :r   keyr
   bytes | Nonec                   |st          d          | j        | t           z  }| j        | t           z  }| j        r | j                            | j                   	 |                                sBt          
                    d|           	 | j        r| j                                         dS dS t          
                    d|           |                                }t          j                                        dd          }|                    |           || j        r| j                                         S S # | j        r| j                                         w w xY w)zRetrieves the cached value for the given key.

    Args:
      key: The key for which the cache value is retrieved.

    Returns:
      The cached data as bytes if available; ``None`` otherwise.
    key cannot be emptytimeoutzCache miss for key: NzCache hit for key:    little)
ValueErrorr   _CACHE_SUFFIX_ATIME_SUFFIXr"   r%   acquirer   existsloggerdebugrelease
read_bytestimetime_nsto_byteswrite_bytes)r'   r)   
cache_path
atime_pathval	timestamps         r   getzLRUCache.getT   s     .,---4]444J4]444J 8
i 6777   3C33444 
	 	  ll000111!!##c,..))!X66iY''' 
	 		 	s    1E 6A.E #E)r@   bytesNonec                T   |st          d          | j        rLt          |          | j        k    r4d|dt          |           d| j         d}t	          j        |           dS | j        | t           z  }| j        | t           z  }| j        r | j	        
                    | j                   	 |                                r%	 | j        r| j	                                         dS dS |                     t          |                     |                    |           t!          j                                        d	d
          }|                    |           | j        r| j	                                         dS dS # | j        r| j	                                         w w xY w)zAdds a new entry to the cache.

    If a cache item with the same key already exists, no action
    will be taken, even if the value is different.

    Args:
      key: The key under which the data will be stored.
      val: The data to be stored.
    r,   zCache value for key z	 of size z) bytes exceeds the maximum cache size of z bytesNr-   additional_sizer/   r0   )r1   r"   lenr   warningswarnr   r2   r3   r%   r4   r   r5   r8   _evict_if_neededr=   r:   r;   r<   )r'   r)   r@   msgr>   r?   rA   s          r   putzLRUCache.putx   s     .,---  SDM!9!9@C @ @CHH @ @*.-@ @ @cmCf4]444J4]444J 8
i 6777					  
	 	  CHH555S!!!,..))!X66iY''' 
	 	 	 	s   3F ,A4F #F'r   rF   rG   c                  | j         sdS g }d}| j                            dt                     D ]}|                                }t
          j        s|j        n|j        }|j	        
                    t                    }| j        | t           z  }t                              |                                d          }	||z  }t          j        ||	||f           | j        |z
  }
||
k    rt          j        |          \  }	}}t&                              d|||
           | j        | t           z  }| j        | t           z  }|                                 |                                 ||z  }||
k    dS dS )a8  Evicts the least recently used items from the cache if necessary
    to ensure the cache does not exceed its maximum size.

    Args:
      additional_size: The size of the new entry being added to the cache.
        This is included to account for the new entry when checking if
        eviction is needed.
    Nr   *r0   zGEvicting cache entry %r: file size %d bytes, target cache size %d bytes)r"   r   globr2   statr   r   st_sizelengthnameremovesuffixr3   r   
from_bytesr9   heapqheappushr   heappopr6   r7   unlink)r'   rG   hdir_sizer>   	file_stat	file_sizer)   r?   
file_atimetarget_sizes              r   rK   zLRUCache._evict_if_needed   s      f %'AHinn%8%8%899 6 6
//##i
 ,3+BX)##	HXiO((77c9#6}666j>>*"7"7"9"98DDj)hnQS)45555-/1K [
 
 #(=#3#3 j#yll 014iN N N 9#6}666j9#6}666j)h [
 
 
 
 
 
 r   N)r   r	   r   r   r   r   )r)   r	   r
   r*   )r)   r	   r@   rC   r
   rD   )rG   r   r
   rD   )__name__
__module____qualname____doc__r(   rB   rM   rK    r   r   r   r   +   s          UW : : : : : :<" " " "H' ' ' 'R 89 - - - - - - - -r   r   )r   r	   r
   r   )
__future__r   rW   loggingr:   typingr   rI   r   __annotations__ImportErrorjax._srcr   r   $jax._src.compilation_cache_interfacer   	getLoggerra   r6   r2   r3   r   r   re   r   r   <module>rn      s)   # " " " " " "              ////   $ % $ $ $ $ $ ? ? ? ? ? ?		8	$	$ 9 9 9 9c c c c c~ c c c c cs   + 33