How to use aiocache - 10 common examples

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_serializers.py View on Github external
def test_init(self):
        serializer = PickleSerializer()
        assert isinstance(serializer, BaseSerializer)
        assert serializer.DEFAULT_ENCODING is None
        assert serializer.encoding is None
github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_init(self):
        serializer = JsonSerializer()
        assert isinstance(serializer, BaseSerializer)
        assert serializer.DEFAULT_ENCODING == "utf-8"
        assert serializer.encoding == "utf-8"
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_serializers.py View on Github external
def test_init(self):
        serializer = MsgPackSerializer()
        assert isinstance(serializer, BaseSerializer)
        assert serializer.DEFAULT_ENCODING == "utf-8"
        assert serializer.encoding == "utf-8"
github argaen / aiocache / tests / ut / test_factory.py View on Github external
def test_new_invalid_cache_raises(self):
        with pytest.raises(InvalidCacheType) as e:
            Cache(object)
        assert str(e.value) == "Invalid cache type, you can only use {}".format(
            list(AIOCACHE_CACHES.keys())
        )
github argaen / aiocache / tests / performance / server.py View on Github external
import asyncio
import argparse
import logging
import uuid
from aiocache import Cache

from aiohttp import web


logging.getLogger("aiohttp.access").propagate = False


AIOCACHE_BACKENDS = {
    "memory": Cache(Cache.MEMORY),
    "redis": Cache(Cache.REDIS),
    "memcached": Cache(Cache.MEMCACHED),
}


class CacheManager:
    def __init__(self, backend):
        self.cache = AIOCACHE_BACKENDS.get(backend)

    async def get(self, key):
        return await self.cache.get(key, timeout=0.1)

    async def set(self, key, value):
        return await self.cache.set(key, value, timeout=0.1)


async def handler_get(req):
    try:
github argaen / aiocache / tests / ut / test_decorators.py View on Github external
            @cached(wrong_param=1)
            async def fn(n):
                return n
github argaen / aiocache / tests / ut / test_decorators.py View on Github external
def test_inheritance(self):
        assert isinstance(cached_stampede(), cached)
github argaen / aiocache / tests / acceptance / test_serializers.py View on Github external
async def test_multi_set_multi_get_types(self, cache, obj):
        cache.serializer = PickleSerializer()
        assert await cache.multi_set([(pytest.KEY, obj)]) is True
        assert await cache.multi_get([pytest.KEY]) == [pickle.loads(pickle.dumps(obj))]
github argaen / aiocache / tests / ut / test_serializers.py View on Github external
def test_dumps(self):
        assert PickleSerializer().dumps("hi") == b"\x80\x03X\x02\x00\x00\x00hiq\x00."