Пример #1
0
    def testDelete(self):
        caching.cache_set('del', value=True)

        for x in range(0,10):
            caching.cache_set('del', 'x', x, value=True)
            for y in range(0,5):
                caching.cache_set('del', 'x', x, 'y', y, value=True)

        # check to make sure all the values are in the cache
        self.assert_(caching.cache_get('del', default=False))
        for x in range(0,10):
            self.assert_(caching.cache_get('del', 'x', x, default=False))
            for y in range(0,5):
                self.assert_(caching.cache_get('del', 'x', x, 'y', y, default=False))

        # try to delete just one
        killed = caching.cache_delete('del','x',1)
        self.assertEqual([caching.CACHE_PREFIX + "::del::x::1"], killed)
        self.assertFalse(caching.cache_get('del', 'x', 1, default=False))

        # but the others are still there
        self.assert_(caching.cache_get('del', 'x', 2, default=False))

        # now kill all of del::x::1
        killed = caching.cache_delete('del','x', 1, children=True)
        for y in range(0,5):
            self.assertFalse(caching.cache_get('del', 'x', 1, 'y', y, default=False))

        # but del::x::2 and children are there
        self.assert_(caching.cache_get('del','x',2,'y',1, default=False))

        # kill the rest
        killed = caching.cache_delete('del', children=True)
        self.assertFalse(caching.cache_get('del',default=False))
        for x in range(0,10):
            self.assertFalse(caching.cache_get('del', 'x', x, default=False))
            for y in range(0,5):
                self.assertFalse(caching.cache_get('del', 'x', x, 'y', y, default=False))
Пример #2
0
 def cache_delete(self, *args, **kwargs):
     key = self.cache_key(*args, **kwargs)
     log.debug("clearing cache for %s", key)
     caching.cache_delete(key, children=True)