当前位置: 首页>>代码示例>>Python>>正文


Python aiocache.cached方法代码示例

本文整理汇总了Python中aiocache.cached方法的典型用法代码示例。如果您正苦于以下问题:Python aiocache.cached方法的具体用法?Python aiocache.cached怎么用?Python aiocache.cached使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在aiocache的用法示例。


在下文中一共展示了aiocache.cached方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_init

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_init(self):
        c = cached(
            ttl=1,
            key="key",
            key_builder="fn",
            cache=SimpleMemoryCache,
            plugins=None,
            alias=None,
            noself=False,
            namespace="test",
        )

        assert c.ttl == 1
        assert c.key == "key"
        assert c.key_builder == "fn"
        assert c.cache is None
        assert c._cache == SimpleMemoryCache
        assert c._serializer is None
        assert c._kwargs == {"namespace": "test"} 
开发者ID:argaen,项目名称:aiocache,代码行数:21,代码来源:test_decorators.py

示例2: reuse_data

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def reuse_data():
    cache = Cache(serializer=JsonSerializer())  # Not ideal to define here
    data = await cache.get("my_custom_key")  # Note the key is defined in `cached` decorator
    return data 
开发者ID:argaen,项目名称:aiocache,代码行数:6,代码来源:sanic_example.py

示例3: decorator

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def decorator(self, mocker, mock_cache):
        with patch("aiocache.decorators._get_cache", return_value=mock_cache):
            yield cached() 
开发者ID:argaen,项目名称:aiocache,代码行数:5,代码来源:test_decorators.py

示例4: test_fails_at_instantiation

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_fails_at_instantiation(self):
        with pytest.raises(TypeError):

            @cached(wrong_param=1)
            async def fn(n):
                return n 
开发者ID:argaen,项目名称:aiocache,代码行数:8,代码来源:test_decorators.py

示例5: test_alias_takes_precedence

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_alias_takes_precedence(self, mock_cache):
        with patch(
            "aiocache.decorators.caches.get", MagicMock(return_value=mock_cache)
        ) as mock_get:
            c = cached(alias="default", cache=SimpleMemoryCache, namespace="test")
            c(stub)

            mock_get.assert_called_with("default")
            assert c.cache is mock_cache 
开发者ID:argaen,项目名称:aiocache,代码行数:11,代码来源:test_decorators.py

示例6: test_keeps_signature

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_keeps_signature(self, mock_cache):
        with patch("aiocache.decorators._get_cache", return_value=mock_cache):

            @cached()
            async def what(self, a, b):
                return "1"

            assert what.__name__ == "what"
            assert str(inspect.signature(what)) == "(self, a, b)"
            assert inspect.getfullargspec(what.__wrapped__).args == ["self", "a", "b"] 
开发者ID:argaen,项目名称:aiocache,代码行数:12,代码来源:test_decorators.py

示例7: test_reuses_cache_instance

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_reuses_cache_instance(self):
        with patch("aiocache.decorators._get_cache") as get_c:
            cache = MagicMock(spec=BaseCache)
            get_c.side_effect = [cache, None]

            @cached()
            async def what():
                pass

            await what()
            await what()

            assert get_c.call_count == 1
            assert cache.get.call_count == 2 
开发者ID:argaen,项目名称:aiocache,代码行数:16,代码来源:test_decorators.py

示例8: test_cache_per_function

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_cache_per_function(self):
        @cached()
        async def foo():
            pass

        @cached()
        async def bar():
            pass

        assert foo.cache != bar.cache 
开发者ID:argaen,项目名称:aiocache,代码行数:12,代码来源:test_decorators.py

示例9: test_inheritance

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_inheritance(self):
        assert isinstance(cached_stampede(), cached) 
开发者ID:argaen,项目名称:aiocache,代码行数:4,代码来源:test_decorators.py

示例10: test_cached_ttl

# 需要导入模块: import aiocache [as 别名]
# 或者: from aiocache import cached [as 别名]
def test_cached_ttl(self, cache):
        @cached(ttl=1, key=pytest.KEY)
        async def fn():
            return str(random.randint(1, 50))

        resp1 = await fn()
        resp2 = await fn()

        assert await cache.get(pytest.KEY) == resp1 == resp2
        await asyncio.sleep(1)
        assert await cache.get(pytest.KEY) is None 
开发者ID:argaen,项目名称:aiocache,代码行数:13,代码来源:test_decorators.py


注:本文中的aiocache.cached方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。