
    $                     P    d Z ddlmZ ddlmZ ddlmZ ddlZ G d d      Zd	dZy)
z3Utilities for caching the result of function calls.    )absolute_import)division)unicode_literalsNc                   "    e Zd ZdZd Zd Zd Zy)FakeLruCachez>Doesn't actually cache but supports LRU interface in Python 2.c                     || _         y N	_function)selffunctions     6lib/googlecloudsdk/core/cache/function_result_cache.py__init__zFakeLruCache.__init__   s	    DN    c                      y)zFExposes this function of actual LRU to avoid missing attribute errors.N )r   s    r   cache_clearzFakeLruCache.cache_clear   s    r   c                 &     | j                   |i |S r	   r
   )r   argskwargss      r   __call__zFakeLruCache.__call__"   s    4>>4*6**r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r      s    F	+r   r   c                       fd}|S )a  Returns cached result if function was run with same args before.

  Wraps functools.lru_cache, so it's not referenced at import in Python 2 and
  unsupported Python 3 distributions.

  Args:
    maxsize (int|None): From Python functools docs: "...saves up to the maxsize
      most recent calls... If maxsize is set to None, the LRU feature is
      disabled and the cache can grow without bound."

  Returns:
    Wrapped functools.lru_cache.
  c                 t    t        t        dd       r t        j                        |       S t        |       S )N	lru_cache)maxsize)getattr	functoolsr   r   )r   r   s    r   _wrapperzlru.<locals>._wrapper5   s2    y+t,1Y  1(;;!!r   r   )r   r"   s   ` r   lrur#   &   s    "
 
/r   )   )r   
__future__r   r   r   r!   r   r#   r   r   r   <module>r&      s%    : &  ' + +r   