def testCacheHit(self): cache = TransientCache(1) cache['key'] = 'value' self.assertTrue('key' in cache) self.assertEqual('value', cache['key'])
def __init__(self, worldPath): if(not os.path.isdir(worldPath)): raise ValueError() self.worldPath = worldPath self.regionsCache = TransientCache(4) self.brokenPos = set()
def __init__(self, regionPath): if(not os.path.isfile(regionPath)): raise ValueError() self.regionPath = regionPath self.sectorsCache = TransientCache(3 * 3 * 3)
def testCacheMissBecauseOfCacheCleanup(self): cache = TransientCache(1) cache['keyOld'] = 'valueOld' cache['keyNew'] = 'valueNew' self.assertFalse('keyOld' in cache) self.assertTrue('keyNew' in cache)
def testExceptionOnSettingEntryAfterCleanup(self): cache = TransientCache(1) cache['keyOld'] = 'valueOld' cache['keyMid'] = 'valueMid' cache['keyNew'] = 'valueNew' self.assertFalse('keyOld' in cache) self.assertFalse('keyMid' in cache) self.assertTrue('keyNew' in cache)
def testGetItemKeepsItemLongerInCache(self): cache = TransientCache(2) cache['keyOldOftenAccess'] = 'valueOld' cache['keyOldRareAccess'] = 'valueOld' cache['keyOldOftenAccess'] cache['keyNew'] = 'valueNew' self.assertTrue('keyOldOftenAccess' in cache)
def testCacheMissBecauseItemNotInCache(self): cache = TransientCache(1) self.assertFalse('key' in cache) self.assertRaises(KeyError, cache.__getitem__, 'key')