googleapiclient.discovery_cache

Package googleapiclient :: Package discovery_cache |
[hide private]
[frames] | no frames]

# Source Code for Package googleapiclient.discovery_cache

     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
    17  from __future__ import absolute_import
    18
    19  import logging
    20  import datetime
    21
    22  DISCOVERY_DOC_MAX_AGE = 60 * 60 * 24  # 1 day
    23
    24
    25 -def autodetect():
    26    """Detects an appropriate cache module and returns it.
    27
    28    Returns:
    29      googleapiclient.discovery_cache.base.Cache, a cache object which
    30      is auto detected, or None if no cache object is available.
    31    """
    32    try:
    33      from google.appengine.api import memcache
    34      from . import appengine_memcache
    35      return appengine_memcache.cache
    36    except Exception:
    37      try:
    38        from . import file_cache
    39        return file_cache.cache
    40      except Exception as e:
    41        logging.warning(e, exc_info=True)
    42        return None
    43