b.f.FIFOSizeCache(FIFOCache) : class documentation

Part of bzrlib.fifo_cache View In Hierarchy

An FIFOCache that removes things based on the size of the values.

This differs in that it doesn't care how many actual items there are, it restricts the cache to be cleaned based on the size of the data.

Method __init__ Create a new FIFOSizeCache.
Method add Add a new value to the cache.
Method cache_size Get the number of bytes we will cache.
Method cleanup Clear the cache until it shrinks to the requested size.
Method resize Increase/decrease the amount of cached data.
Method _remove Remove an entry, making sure to maintain the invariants.

Inherited from FIFOCache:

Method __setitem__ Add a value to the cache, there will be no cleanup function.
Method __delitem__ Undocumented
Method clear Clear out all of the cache.
Method copy Undocumented
Method pop Undocumented
Method popitem Undocumented
Method setdefault similar to dict.setdefault
Method update Similar to dict.update()
Method _remove_oldest Remove the oldest entry.
def __init__(self, max_size=1024 * 1024, after_cleanup_size=None, compute_size=None):
Create a new FIFOSizeCache.
Parametersmax_sizeThe max number of bytes to store before we start clearing out entries.
after_cleanup_sizeAfter cleaning up, shrink everything to this size (defaults to 80% of max_size).
compute_sizeA function to compute the size of a value. If not supplied we default to 'len'.
def add(self, key, value, cleanup=None):
Add a new value to the cache.

Also, if the entry is ever removed from the queue, call cleanup. Passing it the key and value being removed.

ParameterskeyThe key to store it under
valueThe object to store, this value by itself is >= after_cleanup_size, then we will not store it at all.
cleanupNone or a function taking (key, value) to indicate 'value' sohuld be cleaned up.
def cache_size(self):
Get the number of bytes we will cache.
def cleanup(self):
Clear the cache until it shrinks to the requested size.

This does not completely wipe the cache, just makes sure it is under the after_cleanup_size.

def _remove(self, key):
Remove an entry, making sure to maintain the invariants.
def resize(self, max_size, after_cleanup_size=None):
Increase/decrease the amount of cached data.
Parametersmax_sizeThe maximum number of bytes to cache.
after_cleanup_sizeAfter cleanup, we should have at most this many bytes cached. This defaults to 80% of max_size.
API Documentation for Bazaar, generated by pydoctor at 2022-06-16 00:25:16.