示例#1
0
 def testPutDoesntCopyByDefault(self):
     cache = MaybeCacher()
     cache.make_cache("cache1", 5, 5)
     obj = [1, 2, 3]
     # We put this into the cache manually to avoid a false pass from something .get does
     cache.put("cache1", "foo", obj)
     cached_obj = cache.caches["cache1"].data["foo"][1]
     self.assertEquals(id(obj), id(cached_obj))
示例#2
0
 def testPutDoesntCopyByDefault(self):
     cache = MaybeCacher()
     cache.make_cache("cache1", 5, 5)
     obj = [1, 2, 3]
     # We put this into the cache manually to avoid a false pass from something .get does
     cache.put("cache1", "foo", obj)
     cached_obj = cache.caches["cache1"].data["foo"][1]
     self.assertEqual(id(obj), id(cached_obj))
示例#3
0
 def testNoCaching(self):
     with mock.patch("auslib.util.cache.ExpiringLRUCache") as lru:
         cache = MaybeCacher(maxsize=0, timeout=0)
         cache.put("cache1", "foo", "bar")
         # Nothing should be in the cache, because there _isn't_ one.
         self.assertEquals(cache.get("cache1", "foo"), None)
         # And the underlying cache object should not have been touched.
         self.assertFalse(lru.put.called)
         self.assertFalse(lru.get.called)
示例#4
0
 def testCopyOnPut(self):
     cache = MaybeCacher()
     cache.make_cache("cache1", 5, 5)
     cache.make_copies = True
     obj = [1, 2, 3]
     # We put this into the cache manually to avoid a false pass from something .get does
     cache.put("cache1", "foo", obj)
     cached_obj = cache.caches["cache1"].data["foo"]
     self.assertNotEquals(id(obj), id(cached_obj))
示例#5
0
 def testNoCaching(self):
     with mock.patch("auslib.util.cache.ExpiringLRUCache") as lru:
         cache = MaybeCacher(maxsize=0, timeout=0)
         cache.put("cache1", "foo", "bar")
         # Nothing should be in the cache, because there _isn't_ one.
         self.assertEquals(cache.get("cache1", "foo"), None)
         # And the underlying cache object should not have been touched.
         self.assertFalse(lru.put.called)
         self.assertFalse(lru.get.called)
示例#6
0
 def testCopyOnPut(self):
     cache = MaybeCacher()
     cache.make_cache("cache1", 5, 5)
     cache.make_copies = True
     obj = [1, 2, 3]
     # We put this into the cache manually to avoid a false pass from something .get does
     cache.put("cache1", "foo", obj)
     cached_obj = cache.caches["cache1"].data["foo"]
     self.assertNotEqual(id(obj), id(cached_obj))
示例#7
0
 def testCacheExpired(self):
     cache = MaybeCacher(maxsize=5, timeout=5)
     # In order to avoid tests failing due to clock skew or other
     # issues with system clocks we can mock time.time() and make sure
     # it always returns a difference large enough to force a cache expiry
     with mock.patch("time.time") as t:
         t.return_value = 100
         cache.put("cache1", "foo", "bar")
         t.return_value = 200
         self.assertEquals(cache.get("cache1", "foo"), None)
示例#8
0
 def testCacheExpired(self):
     cache = MaybeCacher(maxsize=5, timeout=5)
     # In order to avoid tests failing due to clock skew or other
     # issues with system clocks we can mock time.time() and make sure
     # it always returns a difference large enough to force a cache expiry
     with mock.patch("time.time") as t:
         t.return_value = 100
         cache.put("cache1", "foo", "bar")
         t.return_value = 200
         self.assertEquals(cache.get("cache1", "foo"), None)
示例#9
0
 def testSimpleCache(self):
     cache = MaybeCacher(maxsize=5, timeout=5)
     cache.put("cache1", "foo", "bar")
     self.assertEquals(cache.get("cache1", "foo"), "bar")
示例#10
0
 def testSimpleCache(self):
     cache = MaybeCacher()
     cache.make_cache("cache1", 5, 5)
     cache.put("cache1", "foo", "bar")
     self.assertEquals(cache.get("cache1", "foo"), "bar")
示例#11
0
 def testSimpleCache(self):
     cache = MaybeCacher(maxsize=5, timeout=5)
     cache.put("cache1", "foo", "bar")
     self.assertEquals(cache.get("cache1", "foo"), "bar")
示例#12
0
 def testSimpleCache(self):
     cache = MaybeCacher()
     cache.make_cache("cache1", 5, 5)
     cache.put("cache1", "foo", "bar")
     self.assertEqual(cache.get("cache1", "foo"), "bar")