Beispiel #1
0
    def test_size_limit(self):
        cache = CacheDict(max_size_in_bytes=900)
        value = dict(v=100)

        cache.set_multi(['v1'], value)
        cache.set_multi(['v2'], value)
        cache.set_multi(['v3'], value)
        self.assertEqual(set(('v1', 'v2', 'v3')), set(cache.keys()))

        # setting another key will evict the oldest value
        cache.set_multi(['v4'], value)
        self.assertEqual(set(('v2', 'v3', 'v4')), set(cache.keys()))
Beispiel #2
0
    def test_priorities(self):
        cache = CacheDict(max_size_in_bytes=900)
        value = dict(v=100)

        cache.set_multi(['v1'], value)
        cache.set_multi(['v2'], value)
        cache.set_multi(['v3'], value)
        cache['v1']
        cache.set_multi(['v4'], value)
        cache.set_multi(['v5'], value)
        cache['v1']
        cache.set_multi(['v6'], value)

        self.assertEqual(set(('v1', 'v5', 'v6')), set(cache.keys()))
Beispiel #3
0
    def test_size_limit(self):
        cache = CacheDict(max_size_in_bytes=900)
        value = dict(v=100)

        cache.set_multi(['v1'], value)
        cache.set_multi(['v2'], value)
        cache.set_multi(['v3'], value)
        self.assertEqual(set(('v1', 'v2', 'v3')), set(cache.keys()))

        # setting another key will evict the oldest value
        cache.set_multi(['v4'], value)
        self.assertEqual(set(('v2', 'v3', 'v4')), set(cache.keys()))
Beispiel #4
0
    def test_priorities(self):
        cache = CacheDict(max_size_in_bytes=900)
        value = dict(v=100)

        cache.set_multi(['v1'], value)
        cache.set_multi(['v2'], value)
        cache.set_multi(['v3'], value)
        cache['v1']
        cache.set_multi(['v4'], value)
        cache.set_multi(['v5'], value)
        cache['v1']
        cache.set_multi(['v6'], value)

        self.assertEqual(set(('v1', 'v5', 'v6')), set(cache.keys()))