Esempio n. 1
0
    def testCacheHit(self):
        cache = TransientCache(1)

        cache['key'] = 'value'

        self.assertTrue('key' in cache)
        self.assertEqual('value', cache['key'])
Esempio n. 2
0
    def __init__(self, worldPath):
        if(not os.path.isdir(worldPath)):
            raise ValueError()

        self.worldPath = worldPath
        self.regionsCache = TransientCache(4)
        self.brokenPos = set()
Esempio n. 3
0
    def __init__(self, regionPath):
        if(not os.path.isfile(regionPath)):
            raise ValueError()

        self.regionPath = regionPath

        self.sectorsCache = TransientCache(3 * 3 * 3)
Esempio n. 4
0
    def testCacheMissBecauseOfCacheCleanup(self):
        cache = TransientCache(1)

        cache['keyOld'] = 'valueOld'
        cache['keyNew'] = 'valueNew'

        self.assertFalse('keyOld' in cache)
        self.assertTrue('keyNew' in cache)
Esempio n. 5
0
    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)
Esempio n. 6
0
    def testGetItemKeepsItemLongerInCache(self):
        cache = TransientCache(2)

        cache['keyOldOftenAccess'] = 'valueOld'
        cache['keyOldRareAccess'] = 'valueOld'

        cache['keyOldOftenAccess']

        cache['keyNew'] = 'valueNew'

        self.assertTrue('keyOldOftenAccess' in cache)
Esempio n. 7
0
    def testCacheMissBecauseItemNotInCache(self):
        cache = TransientCache(1)

        self.assertFalse('key' in cache)
        self.assertRaises(KeyError, cache.__getitem__, 'key')