def test_set_and_get_with_expiration(self): self.assertTrue(Cache.set(self.key, self.value, time=1, namespace=self.namespace)) cached_value = Cache.get(self.key, namespace=self.namespace) self.assertEquals(self.value, cached_value) time.sleep(1) self.assertFalse(Cache.get(self.key, namespace=self.namespace))
def test_get_with_delete_expired(self): millenium_unixtime = 946706400 # Set the already expired item self.assertTrue(Cache.set(self.key, self.value, time=millenium_unixtime)) # Check if it exists in the Datastore self.assertTrue(Item.all().filter('cache_key =', self.key).get()) # Try to get it should return None, but force to keep the item self.assertEquals(Cache.get(self.key, delete_expired=False), None) # Check again if it exists in the Datastore self.assertTrue(Item.all().filter('cache_key =', self.key).get()) # Try to get it should return None and delete the item self.assertEquals(Cache.get(self.key), None) # Check again if it exists in the Datastore, it should have been del. self.assertFalse(Item.all().filter('cache_key =', self.key).get())