Beispiel #1
0
 def test_key_expiration(self):
     clock = FakeClock(0.0)
     cache = utils.ExpiringCache(ttl=1.0, clock=clock)
     cache['the answer'] = 42
     clock.now = 0.999999
     self.assertEqual(42, cache['the answer'])
     clock.now = 1.0
     self.assertEqual(None, cache.get('the answer'))
     clock.now = 1.000001
     self.assertEqual(None, cache.get('the answer'))
Beispiel #2
0
    def test_nonzero_full_expiration(self):
        clock = FakeClock(0.0)
        cache = utils.ExpiringCache(ttl=1.0, clock=clock)

        ITEMS = 10
        for i in range(ITEMS):
            cache[i] = 'foobar-%d' % i
        self.assertTrue(cache)

        clock.now = 1.1
        self.assertFalse(cache)
Beispiel #3
0
    def test_nonzero_partial_expiration(self):
        clock = FakeClock(0.0)
        cache = utils.ExpiringCache(ttl=2.0, clock=clock)

        cache['a'] = 1
        clock.now = 1.0
        self.assertTrue(cache)

        cache['b'] = 2
        clock.now = 2.0
        self.assertTrue(cache)

        clock.now = 3.0
        self.assertFalse(cache)
Beispiel #4
0
 def setUp(self):
     self.cache = utils.ExpiringCache(ttl=20)