本文整理汇总了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
示例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)
示例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)
示例4: cache
# 需要导入模块: import cachetools [as 别名]
# 或者: from cachetools import Cache [as 别名]
def cache(self, minsize):
return cachetools.Cache(maxsize=minsize)
示例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))