How to use the aiocache.multi_cached function in aiocache

To help you get started, we’ve selected a few aiocache 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 argaen / aiocache / tests / ut / test_decorators.py View on Github external
def test_init(self):
        mc = multi_cached(
            keys_from_attr="keys",
            key_builder=None,
            ttl=1,
            cache=SimpleMemoryCache,
            plugins=None,
            alias=None,
            namespace="test",
        )

        assert mc.ttl == 1
        assert mc.key_builder("key", lambda x: x) == "key"
        assert mc.keys_from_attr == "keys"
        assert mc.cache is None
        assert mc._cache == SimpleMemoryCache
        assert mc._serializer is None
        assert mc._kwargs == {"namespace": "test"}
github argaen / aiocache / tests / ut / test_decorators.py View on Github external
        @multi_cached(keys_from_attr="keys")
        async def what(self, keys=None, what=1):
            return "1"
github argaen / aiocache / tests / ut / test_decorators.py View on Github external
def test_alias_takes_precedence(self, mock_cache):
        with patch(
            "aiocache.decorators.caches.get", MagicMock(return_value=mock_cache)
        ) as mock_get:
            mc = multi_cached(
                keys_from_attr="keys", alias="default", cache=SimpleMemoryCache, namespace="test"
            )
            mc(stub_dict)

            mock_get.assert_called_with("default")
            assert mc.cache is mock_cache
github argaen / aiocache / tests / ut / test_decorators.py View on Github external
def decorator(self, mocker, mock_cache):
        with patch("aiocache.decorators._get_cache", return_value=mock_cache):
            yield multi_cached(keys_from_attr="keys")
github argaen / aiocache / tests / ut / test_decorators.py View on Github external
            @multi_cached(wrong_param=1)
            async def fn(n):
                return n
github argaen / aiocache / tests / acceptance / test_decorators.py View on Github external
        @multi_cached(keys_from_attr="keys", key_builder=build_key)
        async def fn(self, keys, market="ES"):
            return {pytest.KEY: 1, pytest.KEY_1: 2}
github argaen / aiocache / examples / multicached_decorator.py View on Github external
@multi_cached("ids", cache=Cache.REDIS, namespace="main")
async def multi_cached_ids(ids=None):
    return {id_: DICT[id_] for id_ in ids}