1   
 2   
 3   
 4   
 5   
 6   
 7   
 8   
 9   
10   
11   
12   
13   
14   
15  """Caching utility for the discovery document.""" 
16   
17  from __future__ import absolute_import 
18   
19  import logging 
20  import datetime 
21  import os 
22   
23  LOGGER = logging.getLogger(__name__) 
24   
25  DISCOVERY_DOC_MAX_AGE = 60 * 60 * 24   
26   
27   
29      """Detects an appropriate cache module and returns it. 
30   
31    Returns: 
32      googleapiclient.discovery_cache.base.Cache, a cache object which 
33      is auto detected, or None if no cache object is available. 
34    """ 
35      if 'APPENGINE_RUNTIME' in os.environ: 
36          try: 
37              from google.appengine.api import memcache 
38              from . import appengine_memcache 
39   
40              return appengine_memcache.cache 
41          except Exception: 
42              pass 
43      try: 
44          from . import file_cache 
45   
46          return file_cache.cache 
47      except Exception as e: 
48          LOGGER.warning(e, exc_info=True) 
49          return None 
 50