Rev 3892: Add resize() functionality to the FIFO Cache. in http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache

John Arbash Meinel john at arbash-meinel.com
Wed Dec 10 22:27:18 GMT 2008


At http://bzr.arbash-meinel.com/branches/bzr/1.11/xml_cache

------------------------------------------------------------
revno: 3892
revision-id: john at arbash-meinel.com-20081210222654-7sem2ud7397cd8vg
parent: john at arbash-meinel.com-20081210213712-82i1n0uem1crrnoh
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: xml_cache
timestamp: Wed 2008-12-10 16:26:54 -0600
message:
  Add resize() functionality to the FIFO Cache.
-------------- next part --------------
=== modified file 'bzrlib/fifo_cache.py'
--- a/bzrlib/fifo_cache.py	2008-12-10 00:07:33 +0000
+++ b/bzrlib/fifo_cache.py	2008-12-10 22:26:54 +0000
@@ -73,6 +73,10 @@
         if len(self) > self._max_cache:
             self.cleanup()
 
+    def cache_size(self):
+        """Get the number of entries we will cache."""
+        return self._max_cache
+
     def cleanup(self):
         """Clear the cache until it shrinks to the requested size.
 
@@ -108,6 +112,21 @@
         key = self._queue.popleft()
         self._remove(key)
 
+    def resize(self, max_cache, after_cleanup_count=None):
+        """Increase/decrease the number of cached entries.
+
+        :param max_cache: The maximum number of entries to cache.
+        :param after_cleanup_count: After cleanup, we should have at most this
+            many entries. This defaults to 80% of max_cache.
+        """
+        self._max_cache = max_cache
+        if after_cleanup_count is None:
+            self._after_cleanup_count = max_cache * 8 / 10
+        else:
+            self._after_cleanup_count = min(max_cache, after_cleanup_count)
+        if len(self) > self._max_cache:
+            self.cleanup()
+
     # raise NotImplementedError on dict functions that would mutate the cache
     # which have not been properly implemented yet.
     def copy(self):
@@ -211,6 +230,10 @@
             # Time to cleanup
             self.cleanup()
 
+    def cache_size(self):
+        """Get the number of bytes we will cache."""
+        return self._max_size
+
     def cleanup(self):
         """Clear the cache until it shrinks to the requested size.
 
@@ -226,3 +249,20 @@
         val = FIFOCache._remove(self, key)
         self._value_size -= self._compute_size(val)
         return val
+
+    def resize(self, max_size, after_cleanup_size=None):
+        """Increase/decrease the amount of cached data.
+
+        :param max_size: The maximum number of bytes to cache.
+        :param after_cleanup_size: After cleanup, we should have at most this
+            many bytes cached. This defaults to 80% of max_size.
+        """
+        FIFOCache.resize(self, max_size)
+        self._max_size = max_size
+        if after_cleanup_size is None:
+            self._after_cleanup_size = max_size * 8 / 10
+        else:
+            self._after_cleanup_size = min(max_size, after_cleanup_size)
+        if self._value_size > self._max_size:
+            self.cleanup()
+



More information about the bazaar-commits mailing list