1# Copyright 2014 Google Inc. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14 15"""Caching utility for the discovery document.""" 16 17from __future__ import absolute_import 18 19import logging 20import datetime 21 22 23LOGGER = logging.getLogger(__name__) 24 25DISCOVERY_DOC_MAX_AGE = 60 * 60 * 24 # 1 day 26 27 28def autodetect(): 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 try: 36 from google.appengine.api import memcache 37 from . import appengine_memcache 38 39 return appengine_memcache.cache 40 except Exception: 41 try: 42 from . import file_cache 43 44 return file_cache.cache 45 except Exception as e: 46 LOGGER.warning(e, exc_info=True) 47 return None 48