B
    T^nTn
  ã               @   s6   d Z dZddlmZ ddlmZ dd
d„Zdd„ ZdS )a‘   C implementation of LRU caching.

Provides 2 LRU caching function decorators:

clru_cache - built-in (faster)
           >>> from fastcache import clru_cache
           >>> @clru_cache(maxsize=128,typed=False)
           ... def f(a, b):
           ...     return (a, ) + (b, )
           ...
           >>> type(f)
           >>> <class 'fastcache.clru_cache'>

lru_cache  - python wrapper around clru_cache (slower)
           >>> from fastcache import lru_cache
           >>> @lru_cache(maxsize=128,typed=False)
           ... def f(a, b):
           ...     return (a, ) + (b, )
           ...
           >>> type(f)
           >>> <class 'function'>
z1.0.2é   )Ú
clru_cacheé    )Úupdate_wrapperé€   FNÚerrorc                s   ‡ ‡‡‡fdd„}|S )aó  Least-recently-used cache decorator.

    If *maxsize* is set to None, the LRU features are disabled and
    the cache can grow without bound.

    If *typed* is True, arguments of different types will be cached
    separately. For example, f(3.0) and f(3) will be treated as distinct
    calls with distinct results.

    If *state* is a list or dict, the items will be incorporated into
    argument hash.

    The result of calling the cached function with unhashable (mutable)
    arguments depends on the value of *unhashable*:

        If *unhashable* is 'error', a TypeError will be raised.

        If *unhashable* is 'warning', a UserWarning will be raised, and
        the wrapped function will be called with the supplied arguments.
        A miss will be recorded in the cache statistics.

        If *unhashable* is 'ignore', the wrapped function will be called
        with the supplied arguments. A miss will will be recorded in
        the cache statistics.

    View the cache statistics named tuple (hits, misses, maxsize, currsize)
    with f.cache_info().  Clear the cache and statistics with
    f.cache_clear(). Access the underlying function with f.__wrapped__.

    See:  http://en.wikipedia.org/wiki/Cache_algorithms#Least_Recently_Used

    c                s>   t ˆˆˆˆƒ| ƒ‰ ‡ fdd„}| |_ˆ j|_ˆ j|_t|| ƒS )Nc                 s
   ˆ | |ŽS )N© )ÚargsÚkwargs)Ú_cached_funcr   ú1lib/python3.7/site-packages/fastcache/__init__.pyÚwrapperB   s    z0lru_cache.<locals>.func_wrapper.<locals>.wrapper)r   Ú__wrapped__Ú
cache_infoÚcache_clearr   )Úfuncr   )ÚmaxsizeÚstateÚtypedÚ
unhashable)r
   r   Úfunc_wrapper?   s    zlru_cache.<locals>.func_wrapperr   )r   r   r   r   r   r   )r   r   r   r   r   Ú	lru_cache   s    !r   c              G   s6   dd l }dd l}| |j |j t¡¡gt| ƒ ¡ S )Nr   )ÚpytestÚosÚmainÚpathÚdirnameÚabspathÚ__file__Úlist)r   r   r   r   r   r   ÚtestM   s    r   )r   FNr   )Ú__doc__Ú__version__Z	_lrucacher   Ú	functoolsr   r   r   r   r   r   r   Ú<module>   s
   
/