Beispiel #1
0
 def test_size_set(self):
     CacheBase.configure(
         "apps.core.cache.memory.MemoryCache", io_loop=self.io_loop,
         defaults={"max_size": 2})
     cache = CacheBase()
     yield cache.set("somekey", 1)
     yield cache.set("somekey2", 2)
     yield cache.set("somekey3", 3)
     value = yield cache.get("somekey")
     self.assertEqual(value, None)
Beispiel #2
0
    def test_timeout(self):
        CacheBase.configure(
            "apps.core.cache.memory.MemoryCache", io_loop=self.io_loop,
            defaults={"max_size": 2})
        cache = CacheBase()
        yield cache.set("somekey", 1, 1)
        yield cache.set("somekey2", 2, 2)
        yield sleep(2)

        self.assertNotIn("somekey", cache._cache)
        self.assertNotIn("somekey", cache)
Beispiel #3
0
 def test_set(self):
     CacheBase.configure(
         "apps.core.cache.memory.MemoryCache", io_loop=self.io_loop)
     cache = CacheBase(self.io_loop)
     yield cache.set("somekey", 1)
     value = yield cache.get("somekey")
     self.assertEqual(value, 1)
Beispiel #4
0
    def test_bin(self):
        CacheBase.configure("apps.core.cache.redis.RedisCache",
                            defaults=options.cache_options)
        cache = CacheBase(self.io_loop)

        obj = {"asd": 123, "zxc": u"啊"}
        yield cache.set("testkey", obj)

        value = yield cache.get("testkey",)
        self.assertItemsEqual(value, {"asd": 123, "zxc": u"啊"})
        self.assertTrue(isinstance(value["zxc"], unicode))

        obj = {"asd": 123, "zxc": b"\x00\x01\x02"}
        yield cache.set("testkey2", obj)

        value = yield cache.get("testkey2",)
        self.assertTrue(isinstance(value["zxc"], bytes))
        self.assertEquals(value["zxc"], b"\x00\x01\x02")
Beispiel #5
0
 def test_set(self):
     CacheBase.configure("apps.core.cache.redis.RedisCache",
                         defaults=options.cache_options)
     cache = CacheBase(self.io_loop)
     yield cache.set("testkey", "value")
     value = yield cache.get("testkey",)
     self.assertEqual(value, "value")
     yield cache.delete("testkey")
     value = yield cache.get("testkey",)
     self.assertEqual(value, None)
Beispiel #6
0
    def test_set_dict(self):
        CacheBase.configure("apps.core.cache.redis.RedisCache",
                            defaults=options.cache_options)
        cache = CacheBase(self.io_loop)

        obj = {"asd": 123, "zxc": "qwe"}
        yield cache.set("testkey", obj)
        value = yield cache.get("testkey",)
        self.assertEqual(isinstance(value, dict), True)
        self.assertItemsEqual(value, {"asd": 123, "zxc": "qwe"})
        yield cache.delete("testkey")
        value = yield cache.get("testkey",)
        self.assertEqual(value, None)
Beispiel #7
0
    def test_set_object(self):
        CacheBase.configure("apps.core.cache.redis.RedisCache",
                            defaults=options.cache_options)
        cache = CacheBase(self.io_loop)

        obj = A(123123)
        yield cache.set("testkey", obj)
        value = yield cache.get("testkey",)
        self.assertEqual(isinstance(value, A), True)
        self.assertEqual(value.arg, 123123)
        yield cache.delete("testkey")
        value = yield cache.get("testkey",)
        self.assertEqual(value, None)