Exemplo n.º 1
0
    def test_group_cache(self):
        item1_key = "item1"
        item1_value = 1
        item2_key = "item2"
        item2_value = 2
        item3_key = "item3"
        item3_value = 3
        group12_key = "test_group12"
        group3_key = "test_group3"

        self.assertEqual(group_cache.get(item1_key, group12_key), None)
        self.assertEqual(group_cache.get(item2_key, group12_key), None)
        self.assertEqual(group_cache.get(item3_key, group3_key), None)

        group_cache.set(item1_key, group12_key, item1_value, 60)
        group_cache.set(item2_key, group12_key, item2_value, 60)
        group_cache.set(item3_key, group3_key, item3_value, 60)

        self.assertEqual(group_cache.get(item1_key, group12_key), item1_value)
        self.assertEqual(group_cache.get(item2_key, group12_key), item2_value)
        self.assertEqual(group_cache.get(item3_key, group3_key), item3_value)

        group_cache.invalidate(group12_key)

        self.assertEqual(group_cache.get(item1_key, group12_key), None)
        self.assertEqual(group_cache.get(item2_key, group12_key), None)
        self.assertEqual(group_cache.get(item3_key, group3_key), item3_value)
Exemplo n.º 2
0
    def test_group_cache(self):
        item1_key = "item1"
        item1_value = 1
        item2_key = "item2"
        item2_value = 2
        item3_key = "item3"
        item3_value = 3
        group12_key = "test_group12"
        group3_key = "test_group3"

        self.assertEqual(group_cache.get(item1_key, group12_key), None)
        self.assertEqual(group_cache.get(item2_key, group12_key), None)
        self.assertEqual(group_cache.get(item3_key, group3_key), None)

        group_cache.set(item1_key, group12_key, item1_value, 60)
        group_cache.set(item2_key, group12_key, item2_value, 60)
        group_cache.set(item3_key, group3_key, item3_value, 60)

        self.assertEqual(group_cache.get(item1_key, group12_key), item1_value)
        self.assertEqual(group_cache.get(item2_key, group12_key), item2_value)
        self.assertEqual(group_cache.get(item3_key, group3_key), item3_value)

        group_cache.invalidate(group12_key)

        self.assertEqual(group_cache.get(item1_key, group12_key), None)
        self.assertEqual(group_cache.get(item2_key, group12_key), None)
        self.assertEqual(group_cache.get(item3_key, group3_key), item3_value)
Exemplo n.º 3
0
 def _get_obj_from_cache(self):
     return group_cache.get(self.cache_key, self.cache_group)