/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/fifo_cache.py

  • Committer: Jelmer Vernooij
  • Date: 2020-03-22 01:35:14 UTC
  • mfrom: (7490.7.6 work)
  • mto: This revision was merged to the branch mainline in revision 7499.
  • Revision ID: jelmer@jelmer.uk-20200322013514-7vw1ntwho04rcuj3
merge lp:brz/3.1.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""A simple first-in-first-out (FIFO) cache."""
18
18
 
19
 
from __future__ import absolute_import, division
20
 
 
21
19
from collections import deque
22
20
 
23
21
 
32
30
        else:
33
31
            self._after_cleanup_count = min(after_cleanup_count,
34
32
                                            self._max_cache)
35
 
        self._cleanup = {} # map to cleanup functions when items are removed
36
 
        self._queue = deque() # Track when things are accessed
 
33
        self._cleanup = {}  # map to cleanup functions when items are removed
 
34
        self._queue = deque()  # Track when things are accessed
37
35
 
38
36
    def __setitem__(self, key, value):
39
37
        """Add a value to the cache, there will be no cleanup function."""
81
79
            self._remove_oldest()
82
80
        if len(self._queue) != len(self):
83
81
            raise AssertionError('The length of the queue should always equal'
84
 
                ' the length of the dict. %s != %s'
85
 
                % (len(self._queue), len(self)))
 
82
                                 ' the length of the dict. %s != %s'
 
83
                                 % (len(self._queue), len(self)))
86
84
 
87
85
    def clear(self):
88
86
        """Clear out all of the cache."""
169
167
    it restricts the cache to be cleaned based on the size of the data.
170
168
    """
171
169
 
172
 
    def __init__(self, max_size=1024*1024, after_cleanup_size=None,
 
170
    def __init__(self, max_size=1024 * 1024, after_cleanup_size=None,
173
171
                 compute_size=None):
174
172
        """Create a new FIFOSizeCache.
175
173
 
258
256
            self._after_cleanup_size = min(max_size, after_cleanup_size)
259
257
        if self._value_size > self._max_size:
260
258
            self.cleanup()
261