class documentation

class LRUSizeCache(LRUCache):

View In Hierarchy

An LRUCache 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 just restricts the cache to be cleaned up after so much data is stored.

The size of items added will be computed using compute_size(value), which defaults to len() if not supplied.

Method __init__ Create a new LRUSizeCache.
Method add Add a new value to the cache.
Method cleanup Clear the cache until it shrinks to the requested size.
Method resize Change the number of bytes that will be cached.
Method _remove_node Undocumented
Method _update_max_size Undocumented
Instance Variable _after_cleanup_size Undocumented
Instance Variable _compute_size Undocumented
Instance Variable _max_size Undocumented
Instance Variable _value_size Undocumented

Inherited from LRUCache:

Method __contains__ Undocumented
Method __getitem__ Undocumented
Method __len__ Undocumented
Method __setitem__ Add a value to the cache, there will be no cleanup function.
Method cache_size Get the number of entries we will cache.
Method clear Clear out all of the cache.
Method get Undocumented
Method items Get the key:value pairs as a dict.
Method keys Get the list of keys currently cached.
Method _record_access Record that key was accessed.
Method _remove_lru Remove one entry from the lru, and handle consequences.
Method _update_max_cache Undocumented
Method _walk_lru Walk the LRU list, only meant to be used in tests.
Instance Variable _after_cleanup_count Undocumented
Instance Variable _cache Undocumented
Instance Variable _least_recently_used Undocumented
Instance Variable _max_cache Undocumented
Instance Variable _most_recently_used Undocumented
def __init__(self, max_size=1024*1024, after_cleanup_size=None, compute_size=None):

Create a new LRUSizeCache.

Parameters
max_sizeThe max number of bytes to store before we start clearing out entries.
after_cleanup_sizeAfter cleaning up, shrink everything to this size.
compute_sizeA function to compute the size of the values. We use a function here, so that you can pass 'len' if you are just using simple strings, or a more complex function if you are using something like a list of strings, or even a custom object. The function should take the form "compute_size(value) => integer". If not supplied, it defaults 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 cache, call cleanup(key, value).

Parameters
keyThe key to store it under
valueThe object to store
cleanupNone or a function taking (key, value) to indicate 'value' should be cleaned up.
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 resize(self, max_size, after_cleanup_size=None):

Change the number of bytes that will be cached.

def _remove_node(self, node):
def _update_max_size(self, max_size, after_cleanup_size=None):

Undocumented

_after_cleanup_size =

Undocumented

_compute_size =

Undocumented

_max_size =

Undocumented

_value_size: int =

Undocumented