Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if 'storage_class' not in kwargs:
kwargs['storage_class'] = convert_storage(_storage_class)
return sync_factory(*args, **kwargs)
return factory
def factory_doctor(wire_rope) -> None:
callable = wire_rope.callable
if not callable.is_coroutine:
raise TypeError(
"The function for cache '{}' must be an async function.".format(
callable.code.co_name))
class CommonMixinStorage(fbase.BaseStorage): # Working only as mixin
"""General :mod:`asyncio` storage root for BaseStorageMixin."""
@asyncio.coroutine
def get(self, key):
value = yield from self.get_value(key)
return self.rope.decode(value)
@asyncio.coroutine
def set(self, key, value, expire=...):
if expire is ...:
expire = self.rope.config.expire_default
encoded = self.rope.encode(value)
result = yield from self.set_value(key, encoded, expire)
return result
@asyncio.coroutine
@fbase.interface_attrs(
transform_args=transform_cache_page_args, return_annotation=bool)
def has(self, *args, **kwargs):
raise NotImplementedError
# The below implementation is not reliable for the return value `True`.
def get_value(self, key):
value = self.backend.get(key)
if value is None:
raise fbase.NotFound
return value
def get_or_update(self, wire, **kwargs):
key = self.key(wire, **kwargs)
try:
result = yield from wire.storage.get(key)
except fbase.NotFound:
result = yield from self.execute(wire, **kwargs)
yield from wire.storage.set(key, result)
return result