当前位置: 首页>>代码示例>>Python>>正文


Python cachetools.Cache方法代码示例

本文整理汇总了Python中cachetools.Cache方法的典型用法代码示例。如果您正苦于以下问题:Python cachetools.Cache方法的具体用法?Python cachetools.Cache怎么用?Python cachetools.Cache使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在cachetools的用法示例。


在下文中一共展示了cachetools.Cache方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import Cache [as 别名]
def __init__(self, target_executor, cache=None):
    """Creates a new instance of this executor.

    Args:
      target_executor: An instance of `executor_base.Executor`.
      cache: The cache to use (must be an instance of `cachetools.Cache`). If
        unspecified, by default we construct a 1000-element LRU cache.
    """
    py_typecheck.check_type(target_executor, executor_base.Executor)
    if cache is not None:
      py_typecheck.check_type(cache, cachetools.Cache)
    else:
      cache = cachetools.LRUCache(_DEFAULT_CACHE_SIZE)
    self._target_executor = target_executor
    self._cache = cache
    self._num_values_created = 0 
开发者ID:tensorflow,项目名称:federated,代码行数:18,代码来源:caching_executor.py

示例2: __init__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import Cache [as 别名]
def __init__(self, forward_passer):
        self._forward_passer = forward_passer
        cachetools.Cache.__init__(self, 1000000) 
开发者ID:uzh-rpg,项目名称:sips2_open,代码行数:5,代码来源:system.py

示例3: __getitem__

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import Cache [as 别名]
def __getitem__(self, image):
        coded = tuple([image.shape[1]] + image.ravel().tolist())
        return cachetools.Cache.__getitem__(self, coded) 
开发者ID:uzh-rpg,项目名称:sips2_open,代码行数:5,代码来源:system.py

示例4: cache

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import Cache [as 别名]
def cache(self, minsize):
        return cachetools.Cache(maxsize=minsize) 
开发者ID:tkem,项目名称:cachetools,代码行数:4,代码来源:test_wrapper.py

示例5: create

# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import Cache [as 别名]
def create(options, timer=None, use_deque=True):
    """Create a cache specified by ``options``

    ``options`` is an instance of either
    :class:`endpoints_management.control.caches.CheckOptions` or
    :class:`endpoints_management.control.caches.ReportOptions`

    The returned cache is wrapped in a :class:`LockedObject`, requiring it to
    be accessed in a with statement that gives synchronized access

    Example:
      >>> options = CheckOptions()
      >>> synced_cache = make_cache(options)
      >>> with synced_cache as cache:  #  acquire the lock
      ...    cache['a_key'] = 'a_value'

    Args:
      options (object): an instance of either of the options classes

    Returns:
      :class:`cachetools.Cache`: the cache implementation specified by options
        or None: if options is ``None`` or if options.num_entries < 0

    Raises:
       ValueError: if options is not a support type

    """
    if options is None:  # no options, don't create cache
        return None

    if not isinstance(options, (CheckOptions, QuotaOptions, ReportOptions)):
        _logger.error(u'make_cache(): bad options %s', options)
        raise ValueError(u'Invalid options')

    if (options.num_entries <= 0):
        _logger.debug(u"did not create cache, options was %s", options)
        return None

    _logger.debug(u"creating a cache from %s", options)
    if (options.flush_interval > ZERO_INTERVAL):
        # options always has a flush_interval, but may have an expiration
        # field. If the expiration is present, use that instead of the
        # flush_interval for the ttl
        ttl = getattr(options, u'expiration', options.flush_interval)
        cache_cls = DequeOutTTLCache if use_deque else cachetools.TTLCache
        return LockedObject(
            cache_cls(
                options.num_entries,
                ttl=ttl.total_seconds(),
                timer=to_cache_timer(timer)
            ))

    cache_cls = DequeOutLRUCache if use_deque else cachetools.LRUCache
    return LockedObject(cache_cls(options.num_entries)) 
开发者ID:cloudendpoints,项目名称:endpoints-management-python,代码行数:56,代码来源:caches.py


注:本文中的cachetools.Cache方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。