How to use the ring.func.base function in ring

To help you get started, we’ve selected a few ring examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github youknowone / ring / ring / func / asyncio.py View on Github external
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
github youknowone / ring / ring / django.py View on Github external
    @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`.
github youknowone / ring / ring / func / sync.py View on Github external
def get_value(self, key):
        value = self.backend.get(key)
        if value is None:
            raise fbase.NotFound
        return value
github youknowone / ring / ring / func / asyncio.py View on Github external
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