
    
                     2    S r SSKrSSKJr  SSKJr  SS jrg)z0Common utilities for using the persistent cache.    N)	resources)
exceptionsc                    ^ ^ U U4S jnU$ )a  Decorator to cache the result of a function.

The decorated function must return a resource.

The returned function will take three arguments:
  cache: a Cache object.
  key: str, the key for the function call in the cache.
  args: tuple (optional), the arguments to pass to the original function. If
    not specified, key will be used.

>>> @CacheResource('sums')
... def Add(value1, value2):
...   print 'adding...'
...   value = value1 + value2
...   return resources.REGISTRY.Parse(str(value), collection='...')
>>> with cache_util.GetCache('resource://') as cache:
...   print Add(cache, '1+4', (1, 4))
...   print Add(cache, '1+4', (1, 4))
adding...
http://example.googleapis.com/v1/foos/5
http://example.googleapis.com/v1/foos/5

Args:
  table_prefix: str, a prefix for the names of the tables in the cache to use
    for these results
  timeout_sec: int, the time (in seconds) for which a table is valid

Returns:
  function, a function that decorates with the appropriate behavior.
c                 P   >^  [         R                  " T 5      SU UU4S jj5       nU$ )z'Wraps a function and caches its result.c                 n  > SR                  T	U5      nU R                  UST
S9n UR                  5       nUS   S   n[        R                  R                  U5      $ ! [        R                   aC    Ub  UOU4nT" U6 nUR                  UR                  5       4/5        UR                  5         Us $ f = f)Nz{}:{}   )columnstimeoutr   )formatTableSelectr   REGISTRYParseURLcache_exceptionsCacheTableExpiredAddRowsSelfLinkValidate)cachekeyargs
table_nametableresulturlreffunctable_prefixtimeout_secs           1lib/googlecloudsdk/command_lib/util/cache_util.pyGetFromCache4CacheResource.<locals>.Wrapper.<locals>.GetFromCache:   s    >>,4jkk*akEe
0 Qil!!**3// // 'tcVDk()*
s   A AB43B4)N)	functoolswraps)r   r!   r   r   s   ` r    WrapperCacheResource.<locals>.Wrapper8   s+    __T0 0 0      )r   r   r%   s   `` r    CacheResourcer)      s    >& 
.r'   )i:	 )__doc__r#   googlecloudsdk.corer   googlecloudsdk.core.cacher   r   r)   r(   r'   r    <module>r-      s     7  ) D2r'   