本文整理匯總了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))