Ejemplo n.º 1
0
 async def test_set(self, r):
     await r.flushdb()
     cache = Cache(r, self.app)
     res = await cache.set(self.key, self.expensive_work(self.data),
                           self.data)
     assert res
     identity = cache._gen_identity(self.key, self.data)
     content = await r.get(identity)
     content = cache._unpack(content)
     assert content == self.data
Ejemplo n.º 2
0
 async def test_set_with_plain_key(self, r):
     await r.flushdb()
     cache = Cache(r, self.app, identity_generator_class=None)
     res = await cache.set(self.key,
                           self.expensive_work(self.data),
                           self.data, expire_time=1)
     assert res
     identity = cache._gen_identity(self.key, self.data)
     assert identity == self.key
     content = await r.get(identity)
     content = cache._unpack(content)
     assert content == self.data
Ejemplo n.º 3
0
 async def test_set_timeout(self, r):
     await r.flushdb()
     cache = Cache(r, self.app)
     res = await cache.set(self.key,
                           self.expensive_work(self.data),
                           self.data, expire_time=1)
     assert res
     identity = cache._gen_identity(self.key, self.data)
     content = await r.get(identity)
     content = cache._unpack(content)
     assert content == self.data
     await asyncio.sleep(1)
     content = await r.get(identity)
     assert content is None
Ejemplo n.º 4
0
 async def test_set_many(self, r):
     await r.flushdb()
     cache = Cache(r, self.app)
     res = await cache.set_many(self.expensive_work(self.data), self.data)
     assert res
     for key, value in self.data.items():
         assert await cache.get(key, self.data) == value
Ejemplo n.º 5
0
 async def test_delete_pattern(self, r):
     await r.flushdb()
     cache = Cache(r, self.app)
     await cache.set_many(self.expensive_work(self.data), self.data)
     res = await cache.delete_pattern('test_*', 10)
     assert res == 3
     content = await cache.get(self.key, self.data)
     assert content is None
Ejemplo n.º 6
0
 async def test_get(self, r):
     await r.flushdb()
     cache = Cache(r, self.app)
     res = await cache.set(self.key,
                           self.expensive_work(self.data),
                           self.data, expire_time=1)
     assert res
     content = await cache.get(self.key, self.data)
     assert content == self.data
Ejemplo n.º 7
0
 async def test_exists(self, r):
     await r.flushdb()
     cache = Cache(r, self.app)
     await cache.set(self.key, self.expensive_work(self.data),
                     self.data, expire_time=1)
     exists = await cache.exist(self.key, self.data)
     assert exists is True
     await asyncio.sleep(1.1)
     exists = await cache.exist(self.key, self.data)
     assert exists is False
Ejemplo n.º 8
0
 async def test_ttl(self, r):
     await r.flushdb()
     cache = Cache(r, self.app)
     await cache.set(self.key, self.expensive_work(self.data),
                     self.data, expire_time=1)
     ttl = await cache.ttl(self.key, self.data)
     assert ttl > 0
     await asyncio.sleep(1.1)
     ttl = await cache.ttl(self.key, self.data)
     assert ttl < 0