
    >ie                        d dl mZ d dlZd dlmZ d dlmZ d dlmZ  ej	        d          dz   ej	        d          dz  z   Z
 G d	 d
e          ZdS )    )annotationsN)Number)default_timer)CallbackgGz?    c                  0    e Zd ZdZd Zd Zd Zd Zd ZdS )Cachea  Use cache for computation

    Examples
    --------

    >>> cache = Cache(1e9)  # doctest: +SKIP

    The cache can be used locally as a context manager around ``compute`` or
    ``get`` calls:

    >>> with cache:  # doctest: +SKIP
    ...     result = x.compute()

    You can also register a cache globally, so that it works for all
    computations:

    >>> cache.register()    # doctest: +SKIP
    >>> cache.unregister()  # doctest: +SKIP
    c                >   	 dd l }nC# t          $ r6}t          d                    t          |                              |d }~ww xY w|j        | _        t          |t                    r |j        |g|R i |}n|s|rJ || _	        t                      | _        d S )Nr   z/Cache requires cachey, "{ex}" problem importing)ex)cacheyImportErrorformatstrnbytes_nbytes
isinstancer   r
   cachedict
starttimes)selfr   argskwargsr   r   s         *lib/python3.11/site-packages/dask/cache.py__init__zCache.__init__!   s    	MMMM 	 	 	DKKsSUwwKWW 	 }eV$$ 	+ FL888888EE*F***
&&s    
A1AAc                    t                      | _        t          |          t          | j        j                  z  }|D ]}| j        j        |         ||<   d S N)r   	durationssetr   data)r   dskoverlapkeys       r   _startzCache._start0   sV    c((S111 	, 	,Czs+CHH	, 	,    c                2    t                      | j        |<   d S r   )r   r   )r   r#   r!   states       r   _pretaskzCache._pretask6   s    ,r%   c                b    t                       j        |         z
  }|d         |         }|r|t           fd|D                       z  }| j        |<                        |          t
          z   t          j        |          dz  z   } j        	                    ||||z  dz  |           d S )Ndependenciesc              3  N   K   | ]}j                             |d           V   dS )r   N)r   get).0kr   s     r   	<genexpr>z"Cache._posttask.<locals>.<genexpr>=   s5      CCDN..q!44CCCCCCr%   r   g    eA)costr   )
r   r   maxr   r   overheadsys	getsizeofr   put)	r   r#   valuer!   r'   iddurationdepsnbs	   `        r   	_posttaskzCache._posttask9   s     ??T_S%99^$S) 	DCCCCdCCCCCCH&s\\%  8+cmC.@.@1.DD
sE2(;BGGGGGr%   c                j    | j                                          | j                                         d S r   )r   clearr   )r   r!   r'   erroreds       r   _finishzCache._finishB   s0    r%   N)	__name__
__module____qualname____doc__r   r$   r(   r;   r?   r   r%   r   r
   r
      sl         (! ! !, , ,/ / /H H H    r%   r
   )
__future__r   r3   numbersr   timeitr   dask.callbacksr   r4   r2   r
   r   r%   r   <module>rH      s    " " " " " " 



                   # # # # # #3="]S]2%6%6%::8 8 8 8 8H 8 8 8 8 8r%   