o
    Ph                     @   sf   d dl Z d dlmZmZ d dlmZmZ d dlmZ e dZ	G dd deZ
dd	ed
efddZdS )    N)	lru_cachewraps)datetime	timedelta)OrderedDicttranslatepyc                       sB   e Zd Zd
 fdd	Z fddZ fddZ fdd	Z  ZS )LRUDictCache   c                    s   || _ t j|i | d S N)maxsizesuper__init__)selfr   argskwds	__class__ W/var/www/html/env_mimamsha/lib/python3.10/site-packages/translatepy/utils/lru_cacher.pyr      s   zLRUDictCache.__init__c                    s   t  |}| | |S r
   )r   __getitem__move_to_end)r   keyvaluer   r   r   r      s   
zLRUDictCache.__getitem__c                    sH   || v r	|  | t || t| | jkr"tt| }| |= d S d S r
   )r   r   __setitem__lenr   nextiter)r   r   r   oldestr   r   r   r      s   

zLRUDictCache.__setitem__c                    s   t    d S r
   )r   clear)r   r   r   r   r      s   zLRUDictCache.clear)r	   )__name__
__module____qualname__r   r   r   r   __classcell__r   r   r   r   r      s
    r      secondsr   c                    s    fdd}|S )Nc                    s@   t   td _t  j  _t  fdd}|S )N)r$   c                    sl   t dt  t d j t  jkr+t d    t  j  _ | g|R i |S )NzTime now: {}z"Cached value's expiration time: {}z;The data in the cache is out of date, clearing the cache...)loggerdebugformatr   utcnow
expirationcache_clearlifetime)r   r   kwargsfuncr   r   wrapped_func)   s   
z<timed_lru_cache.<locals>.wrapper_cache.<locals>.wrapped_func)r   r   r+   r   r(   r)   r   )r.   r/   r   r$   r-   r   wrapper_cache#   s   z&timed_lru_cache.<locals>.wrapper_cacher   )r$   r   r1   r   r0   r   timed_lru_cache"   s   r2   )r#   )logging	functoolsr   r   r   r   collectionsr   	getLoggerr%   r   intr2   r   r   r   r   <module>   s   
