U
    5d                  
   @   s   d Z ddlZddlmZ ddlmZ dd ZG dd deZeej	
d	dej	
d
dej	
ddeej	
ddeej	
dddZdS )zFunction caching    N)Memory)FunctionMakerc                 C   s   t j|dt| |d|dS )Nz"return decfunc(%(shortsignature)s))Zdecfunc)__wrapped__)r   createdict)decfunc r	   2/tmp/pip-unpacked-wheel-8l90aumz/librosa/_cache.py_decorator_apply
   s    r   c                   @   sH   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d Zdd Z	dd Z
dS )CacheManagera)  The librosa cache manager class wraps joblib.Memory
    with a __call__ attribute, so that it may act as a function.

    Additionally, it provides a caching level filter, so that
    different functions can be cached or not depending on the user's
    preference for speed vs. storage usage.
    c                 O   s"   | dd}t||| _|| _d S )Nlevel
   )popr   memoryr   )selfargskwargsr   r	   r	   r
   __init__   s    zCacheManager.__init__c                    s    fdd}|S )zuExample usage:

        @cache(level=2)
        def semi_important_function(some_arguments):
            ...
        c                    s,   j jdk	r$j kr$tj j| S | S dS )zVDecorator function.  Adds an input/output cache to
            the specified function.N)r   locationr   r   cache)functionr   r   r	   r
   wrapper.   s    z&CacheManager.__call__.<locals>.wrapperr	   )r   r   r   r	   r   r
   __call__&   s    	zCacheManager.__call__c                 O   s   | j j||S N)r   clearr   r   r   r	   r	   r
   r   9   s    zCacheManager.clearc                 O   s   | j j||S r   )r   evalr   r	   r	   r
   r   <   s    zCacheManager.evalc                 O   s   | j j||S r   )r   formatr   r	   r	   r
   r   ?   s    zCacheManager.formatc                 O   s   | j j||S r   )r   reduce_sizer   r	   r	   r
   r    B   s    zCacheManager.reduce_sizec                 O   s   | j j||S r   )r   warnr   r	   r	   r
   r!   E   s    zCacheManager.warnN)__name__
__module____qualname____doc__r   r   r   r   r   r    r!   r	   r	   r	   r
   r      s   
r   ZLIBROSA_CACHE_DIRZLIBROSA_CACHE_MMAPZLIBROSA_CACHE_COMPRESSFZLIBROSA_CACHE_VERBOSEZLIBROSA_CACHE_LEVELr   )Z	mmap_modecompressverboser   )r%   osZjoblibr   	decoratorr   r   objectr   environgetintr   r	   r	   r	   r
   <module>   s   	7