o
    €Ï   ã                   @   s4   d dl mZ d dlZddlmZ G dd„ deƒZdS )é    )Úabsolute_importNé   )ÚCachec                   @   sl   e Zd ZdZddd„Zejfdd„Zejfdd„Zejfd	d
„Zdd„ Z	e
ejdƒr0dd„ ZdS dd„ ZdS )ÚLRUCachez/Least Recently Used (LRU) cache implementation.Nc                 C   s   t  | ||¡ t ¡ | _d S ©N)r   Ú__init__ÚcollectionsÚOrderedDictÚ_LRUCache__order)ÚselfÚmaxsizeÚ	getsizeof© r   ú7/tmp/google-cloud-sdk/lib/third_party/cachetools/lru.pyr      s   zLRUCache.__init__c                 C   s   || |ƒ}|   |¡ |S r   ©Ú_LRUCache__update)r   ÚkeyÚcache_getitemÚvaluer   r   r   Ú__getitem__   s   

zLRUCache.__getitem__c                 C   s   || ||ƒ |   |¡ d S r   r   )r   r   r   Úcache_setitemr   r   r   Ú__setitem__   s   zLRUCache.__setitem__c                 C   s   || |ƒ | j |= d S r   )r
   )r   r   Úcache_delitemr   r   r   Ú__delitem__   s   
zLRUCache.__delitem__c                 C   s@   z	t t| jƒƒ}W n ty   td| jj ƒ‚w ||  |¡fS )z>Remove and return the `(key, value)` pair least recently used.z%s is empty)ÚnextÚiterr
   ÚStopIterationÚKeyErrorÚ	__class__Ú__name__Úpop©r   r   r   r   r   Úpopitem   s   ÿzLRUCache.popitemÚmove_to_endc                 C   s2   z	| j  |¡ W d S  ty   d | j |< Y d S w r   )r
   r#   r   r!   r   r   r   Ú__update'   s
   ÿzLRUCache.__updatec                 C   s8   z| j  |¡| j |< W d S  ty   d | j |< Y d S w r   )r
   r    r   r!   r   r   r   r$   .   s
   ÿr   )r   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r"   Úhasattrr   r	   r   r   r   r   r   r      s    
	r   )Ú
__future__r   r   Úcacher   r   r   r   r   r   Ú<module>   s    