def test_lru_with_keyword_args_l1_maxsize_none(self): @utils.lru2cache(l1_maxsize=None, l2cache_name='dummy') def fib(n): if n < 2: return n return fib(n=n-1) + fib(n=n-2) self.assertEqual([fib(n=number) for number in range(16)], [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) self.assertEqual(fib.cache_info(), utils._CacheInfo(l1_hits=28, l1_misses=16, l2_hits=0, l2_misses=16, l1_maxsize=None, l1_currsize=16)) fib.cache_clear() self.assertEqual(fib.cache_info(), utils._CacheInfo(l1_hits=0, l1_misses=0, l2_hits=0, l2_misses=0, l1_maxsize=None, l1_currsize=0))
def test_l2_with_lru_l1_maxsize_zero(self): @utils.lru2cache(l1_maxsize=0) def fib(n): if n < 2: return n return fib(n-1) + fib(n-2) self.assertEqual([fib(n) for n in range(16)], [0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610]) self.assertEqual(fib.cache_info(), utils._CacheInfo(l1_hits=0, l1_misses=44, l2_hits=28, l2_misses=16, l1_maxsize=0, l1_currsize=0)) fib.cache_clear() l2.clear() self.assertEqual(fib.cache_info(), utils._CacheInfo(l1_hits=0, l1_misses=0, l2_hits=0, l2_misses=0, l1_maxsize=0, l1_currsize=0))
def test_invalidations_with_l1_maxsize_none(self): self.n = 2 @utils.lru2cache(l1_maxsize=None, l2cache_name='dummy') def f(x): return x * self.n for self.n in range(2,10): for i in range(1,10): if not self.n & 1: # Test if even f.invalidate(i) # If even invalidate the cache and get actual results self.assertFalse(f(i) & 1) # Assert result is not odd self.assertEqual(f.cache_info(), utils._CacheInfo(l1_hits=36, l1_misses=36, l2_hits=0, l2_misses=36, l1_maxsize=None, l1_currsize=9))