def test_that_cache_items_are_ungettable_once_expired(self):
     timeout = 0.1
     cache = Cache(timeout)
     cache.set("hello", "world")
     self.assertEquals(cache.get("hello"), "world")
     time.sleep(timeout / 2)
     self.assertEquals(cache.get("hello"), "world")
     time.sleep(timeout / 2)
     self.assertRaises(KeyError, cache.get, "hello")
 def test_that_cache_respects_max_size(self):
     timeout = 0.1
     cache = Cache(timeout, max_size=2)
     cache.set("hello", "world")
     self.assertEquals(len(cache), 1)
     cache.set("how", "are")
     self.assertEquals(len(cache), 2)
     cache.set("you", "today?")
     self.assertEquals(len(cache), 2)
     self.assertEquals(cache.get("you"), "today?")
     self.assertEquals(cache.get("how"), "are")
     self.assertRaises(KeyError, cache.get, "hello")
 def test_that_cache_respects_max_size(self):
     timeout = 0.1
     cache = Cache(timeout, max_size=2)
     cache.set("hello", "world")
     self.assertEquals(len(cache), 1)
     cache.set("how", "are")
     self.assertEquals(len(cache), 2)
     cache.set("you", "today?")
     self.assertEquals(len(cache), 2)
     self.assertEquals(cache.get("you"), "today?")
     self.assertEquals(cache.get("how"), "are")
     self.assertRaises(KeyError, cache.get, "hello")
 def test_that_cache_items_are_ungettable_once_expired(self):
     timeout = 0.1
     cache = Cache(timeout)
     cache.set("hello", "world")
     self.assertEquals(cache.get("hello"), "world")
     time.sleep(timeout / 2)
     self.assertEquals(cache.get("hello"), "world")
     time.sleep(timeout / 2)
     self.assertRaises(KeyError, cache.get, "hello")