/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: 2018-06-14 17:59:16 UTC
  • mto: This revision was merged to the branch mainline in revision 7065.
  • Revision ID: jelmer@jelmer.uk-20180614175916-a2e2xh5k533guq1x
Move breezy.plugins.git to breezy.git.

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