def test_memory_cache(self): cache = Cache("MemoryCache") key = [1, 2, 3] value = "hello!" cache.set(key, value, 0) self.assertEqual( cache.get(key), value, "Set value is not equal to returned value") for lifespan in range(1, 3): key = "a key" value = "a value" cache.set(key, value, lifespan) self.assertEqual( cache.get(key), value, "Set value is not equal to returned value") time.sleep(lifespan / 2.0) self.assertEqual( cache.get(key), value, "Set value is not equal to returned value") time.sleep(lifespan / 2.0) self.assertIsNone(cache.get(key), "Key should be expired")
def test_dummy_cache(self): cache = Cache("DummyCache") key = [1, 2, 3] value = "hello!" cache.set(key, value, 0) self.assertIsNone(cache.get(key), "Key should be expired") for lifespan in range(1, 3): key = "a key" value = "a value" cache.set(key, value, lifespan) self.assertIsNone(cache.get(key), "Key should be expired") time.sleep(lifespan)