Beispiel #1
0
    def test_dependents(self):
        dependent_cache_name = self.check_cache_gone('dependent')
        dependent_cache = PersistentCache(dependent_cache_name, cache_manager=self.manager)

        parent_cache_name = self.check_cache_gone('parent')
        parent_cache = PersistentCache(parent_cache_name, cache_manager=self.manager, dependents=[dependent_cache])

        dependent_cache['foo'] = 'bar'
        parent_cache.save(True)
        dependent_cache['foo'] = 'saved'

        parent_cache.load(True)
        self.assertEqual(dependent_cache['foo'], 'bar')

        dependent_cache['foo'] = 'invalid'
        parent_cache.invalidate(True)
        self.assertEqual(dependent_cache['foo'], 'bar')

        parent_cache.delete_saved_content(True)
        parent_cache.load(True)
        self.assertIsNone(dependent_cache.contents)

        parent_cache.load_or_build(True)
        self.assertDictEqual(dependent_cache.contents, {})
        dependent_cache['foo'] = 'bar'
        dependent_cache.save()

        parent_cache.invalidate_and_rebuild(True)
        self.assertDictEqual(dependent_cache.contents, {})
Beispiel #2
0
    def test_invalidate(self):
        cache_name = self.check_cache_gone('invalidate')
        cache = PersistentCache(cache_name, cache_manager=self.manager)
        cache['foo'] = 'bar'
        cache.save()
        cache['baz'] = 'bar'

        cache.invalidate() # Should reload
        self.assertEqual(cache['foo'], 'bar')
        self.assertNotIn('baz', cache)