Format: application/x-python-code
⬇ Download File (7.6 KB)
   1  o
   2  
   3  2'hK�@s*ddlZGdd�d�ZGdd�de�ZdS)�Nc
   4  @s�eZdZdZd)defdd�Zdejedefdd	�Zd
   5  e	dej
   6  fdd�Zd
   7  e	defd
   8  d�Z
   9  de	dejej
  10  fdd�Zde	deje	ej
  11  ffdd�Z	d*d
  12  e	dej
  13  dejedejefdd�Zd*d
  14  e	dej
  15  dejedefdd�Z	d*deje	ej
  16  fdejedejej
  17  fdd�Zde	dejej
  18  fdd�Zd
  19  e	defdd �Zdefd!d"�Zd+d
  20  e	d$edejefd%d&�Zd+d
  21  e	d$edejefd'd(�ZdS),�	BaseCacheaMBaseclass for the cache systems.  All the cache systems implement this
  22      API or a superset of it.
  23  
  24      :param default_timeout: the default timeout (in seconds) that is used if
  25                              no timeout is specified on :meth:`set`. A timeout
  26                              of 0 indicates that the cache never expires.
  27      �,�default_timeoutcCs
  28  ||_dS�N�r)�selfr�r�CC:\Users\shubh\Videos\agent\nova\Lib\site-packages\cachelib/base.py�__init__
  29  s
  30  zBaseCache.__init__�timeout�returncCs|dur|j}|Srr)rrrrr	�_normalize_timeoutszBaseCache._normalize_timeout�keycC�dS)z�Look up key in the cache and return the value for it.
  31  
  32          :param key: the key to be looked up.
  33          :returns: The value if it exists and is readable, else ``None``.
  34          Nr�rrrrr	�getsz
  35  BaseCache.getcCr)z�Delete `key` from the cache.
  36  
  37          :param key: the key to delete.
  38          :returns: Whether the key existed and has been deleted.
  39          :rtype: boolean
  40          Trrrrr	�delete�zBaseCache.delete�keyscs�fdd�|D�S)a<Returns a list of values for the given keys.
  41          For each key an item in the list is created::
  42  
  43              foo, bar = cache.get_many("foo", "bar")
  44  
  45          Has the same error handling as :meth:`get`.
  46  
  47          :param keys: The function accepts multiple keys as positional
  48                       arguments.
  49          csg|]}��|��qSr)r)�.0�k�rrr	�
  50  <listcomp>1sz&BaseCache.get_many.<locals>.<listcomp>r�rrrrr	�get_many&szBaseCache.get_manycGstt||j|���S)z�Like :meth:`get_many` but return a dict::
  51  
  52              d = cache.get_dict("foo", "bar")
  53              foo = d["foo"]
  54              bar = d["bar"]
  55  
  56          :param keys: The function accepts multiple keys as positional
  57                       arguments.
  58          )�dict�ziprrrrr	�get_dict3s
  59  zBaseCache.get_dictN�valuecCr)akAdd a new key/value to the cache (overwrites value, if key already
  60          exists in the cache).
  61  
  62          :param key: the key to set
  63          :param value: the value for the key
  64          :param timeout: the cache timeout for the key in seconds (if not
  65                          specified, it uses the default timeout). A timeout of
  66                          0 indicates that the cache never expires.
  67          :returns: ``True`` if key has been updated, ``False`` for backend
  68                    errors. Pickling errors, however, will raise a subclass of
  69                    ``pickle.PickleError``.
  70          :rtype: boolean
  71          Tr�rrrrrrr	�set?sz
  72  BaseCache.setcCr)aWorks like :meth:`set` but does not overwrite the values of already
  73          existing keys.
  74  
  75          :param key: the key to set
  76          :param value: the value for the key
  77          :param timeout: the cache timeout for the key in seconds (if not
  78                          specified, it uses the default timeout). A timeout of
  79                          0 indicates that the cache never expires.
  80          :returns: Same as :meth:`set`, but also ``False`` for already
  81                    existing keys.
  82          :rtype: boolean
  83          Trrrrr	�addQs
  84  z
  85  BaseCache.add�mappingcCs2g}|��D]\}}|�|||�r|�|�q|S)a�Sets multiple keys and values from a mapping.
  86  
  87          :param mapping: a mapping with the keys/values to set.
  88          :param timeout: the cache timeout for the key in seconds (if not
  89                          specified, it uses the default timeout). A timeout of
  90                          0 indicates that the cache never expires.
  91          :returns: A list containing all keys successfully set
  92          :rtype: boolean
  93          )�itemsr �append)rr"rZset_keysrrrrr	�set_many`s
  94  �zBaseCache.set_manycGs&g}|D]}|�|�r|�|�q|S)z�Deletes multiple keys at once.
  95  
  96          :param keys: The function accepts multiple keys as positional
  97                       arguments.
  98          :returns: A list containing all successfully deleted keys
  99          :rtype: boolean
 100          )rr$)rrZdeleted_keysrrrr	�delete_manyrs
 101  
 102  �zBaseCache.delete_manycCstd��)z�Checks if a key exists in the cache without returning it. This is a
 103          cheap operation that bypasses loading the actual data on the backend.
 104  
 105          :param key: the key to check
 106          z�%s doesn't have an efficient implementation of `has`. That means it is impossible to check whether a key exists without fully loading the key's data. Consider using `self.get` explicitly if you don't care about performance.)�NotImplementedErrorrrrr	�has�s�z
 107  BaseCache.hascCr)z�Clears the cache.  Keep in mind that not all caches support
 108          completely clearing the cache.
 109  
 110          :returns: Whether the cache has been cleared.
 111          :rtype: boolean
 112          Trrrrr	�clear�rzBaseCache.clear��deltacCs&|�|�pd|}|�||�r|SdS)aHIncrements the value of a key by `delta`.  If the key does
 113          not yet exist it is initialized with `delta`.
 114  
 115          For supporting caches this is an atomic operation.
 116  
 117          :param key: the key to increment.
 118          :param delta: the delta to add.
 119          :returns: The new value or ``None`` for backend errors.
 120          rN�rr �rrr+rrrr	�inc��
 121  z
 122  BaseCache.inccCs&|�|�pd|}|�||�r|SdS)aLDecrements the value of a key by `delta`.  If the key does
 123          not yet exist it is initialized with `-delta`.
 124  
 125          For supporting caches this is an atomic operation.
 126  
 127          :param key: the key to increment.
 128          :param delta: the delta to subtract.
 129          :returns: The new value or `None` for backend errors.
 130          rNr,r-rrr	�dec�r/z
 131  BaseCache.dec)rr)r*)�__name__�
 132  __module__�__qualname__�__doc__�intr
 133  �_t�Optionalr
 134  �str�Anyr�boolr�Listr�Dictrr r!r%r&r(r)r.r0rrrr	rs@	
 135  
 136  ����
 137  �$���
 138  
 139  �
 140  	"
 141  rc@s"eZdZdZdedefdd�ZdS)�	NullCachez�A cache that doesn't cache.  This can be useful for unit testing.
 142  
 143      :param default_timeout: a dummy parameter that is ignored but exists
 144                              for API compatibility with other caches.
 145      rrcCr)NFrrrrr	r(�sz
 146  NullCache.hasN)r1r2r3r4r8r:r(rrrr	r=�sr=)�typingr6rr=rrrr	�<module>s.