~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/lru_cache.py

  • Committer: John Arbash Meinel
  • Date: 2008-12-09 22:31:56 UTC
  • mto: This revision was merged to the branch mainline in revision 3887.
  • Revision ID: john@arbash-meinel.com-20081209223156-8usxe0ihbbg4cpjq
Only cache cleanup functions if they aren't None.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
        if key in self._cache:
64
64
            self._remove(key)
65
65
        self._cache[key] = value
66
 
        self._cleanup[key] = cleanup
 
66
        if cleanup is not None:
 
67
            self._cleanup[key] = cleanup
67
68
        self._record_access(key)
68
69
 
69
70
        if len(self._cache) > self._max_cache:
129
130
 
130
131
    def _remove(self, key):
131
132
        """Remove an entry, making sure to maintain the invariants."""
132
 
        cleanup = self._cleanup.pop(key)
 
133
        cleanup = self._cleanup.pop(key, None)
133
134
        val = self._cache.pop(key)
134
135
        if cleanup is not None:
135
136
            cleanup(key, val)
223
224
            return
224
225
        self._value_size += value_len
225
226
        self._cache[key] = value
226
 
        self._cleanup[key] = cleanup
 
227
        if cleanup is not None:
 
228
            self._cleanup[key] = cleanup
227
229
        self._record_access(key)
228
230
 
229
231
        if self._value_size > self._max_size: