Python cachetools.Cache() Examples
The following are 5
code examples of cachetools.Cache().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
cachetools
, or try the search function
.
Example #1
Source File: caching_executor.py From federated with Apache License 2.0 | 6 votes |
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
Example #2
Source File: system.py From sips2_open with GNU General Public License v3.0 | 5 votes |
def __init__(self, forward_passer): self._forward_passer = forward_passer cachetools.Cache.__init__(self, 1000000)
Example #3
Source File: system.py From sips2_open with GNU General Public License v3.0 | 5 votes |
def __getitem__(self, image): coded = tuple([image.shape[1]] + image.ravel().tolist()) return cachetools.Cache.__getitem__(self, coded)
Example #4
Source File: test_wrapper.py From cachetools with MIT License | 5 votes |
def cache(self, minsize): return cachetools.Cache(maxsize=minsize)
Example #5
Source File: caches.py From endpoints-management-python with Apache License 2.0 | 4 votes |
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))