Esempio n. 1
0
async def test_set(r):
    await r.flushdb()

    cache = Cache(r, APP)
    res = await cache.set(KEY, expensive_work(DATA), DATA)
    assert res

    identity = cache._gen_identity(KEY, DATA)
    content = await r.get(identity)
    content = cache._unpack(content)
    assert content == DATA
Esempio n. 2
0
async def test_set_with_plain_key(r):
    await r.flushdb()

    cache = Cache(r, APP, identity_generator_class=None)
    res = await cache.set(KEY, expensive_work(DATA), DATA, expire_time=1)
    assert res

    identity = cache._gen_identity(KEY, DATA)
    assert identity == KEY

    content = await r.get(identity)
    content = cache._unpack(content)
    assert content == DATA
Esempio n. 3
0
async def test_set_timeout(r, event_loop):
    await r.flushdb()

    cache = Cache(r, APP)
    res = await cache.set(KEY, expensive_work(DATA), DATA, expire_time=1)
    assert res

    identity = cache._gen_identity(KEY, DATA)
    content = await r.get(identity)
    content = cache._unpack(content)
    assert content == DATA

    await asyncio.sleep(1.1)
    content = await r.get(identity)
    assert content is None