class documentation

class LRUCache(object):

Known subclasses: dulwich.lru_cache.LRUSizeCache

View In Hierarchy

A class which manages a cache of entries, removing unused ones.

Method __contains__ Undocumented
Method __getitem__ Undocumented
Method __init__ Undocumented
Method __len__ Undocumented
Method __setitem__ Add a value to the cache, there will be no cleanup function.
Method add Add a new value to the cache.
Method cache_size Get the number of entries we will cache.
Method cleanup Clear the cache until it shrinks to the requested size.
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 resize Change the number of entries that will be cached.
Method _record_access Record that key was accessed.
Method _remove_lru Remove one entry from the lru, and handle consequences.
Method _remove_node Undocumented
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 __contains__(self, key):

Undocumented

def __getitem__(self, key):

Undocumented

def __init__(self, max_cache=100, after_cleanup_count=None):

Undocumented

def __len__(self):

Undocumented

def __setitem__(self, key, value):

Add a value to the cache, there will be no cleanup function.

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 cache_size(self):

Get the number of entries 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_count.

def clear(self):

Clear out all of the cache.

def get(self, key, default=None):

Undocumented

def items(self):

Get the key:value pairs as a dict.

def keys(self):

Get the list of keys currently cached.

Note that values returned here may not be available by the time you request them later. This is simply meant as a peak into the current state.

Returns: An unordered list of keys that are currently cached.

def resize(self, max_cache, after_cleanup_count=None):

Change the number of entries that will be cached.

def _record_access(self, node):

Record that key was accessed.

def _remove_lru(self):

Remove one entry from the lru, and handle consequences.

If there are no more references to the lru, then this entry should be removed from the cache.

def _remove_node(self, node):

Undocumented

def _update_max_cache(self, max_cache, after_cleanup_count=None):

Undocumented

def _walk_lru(self):

Walk the LRU list, only meant to be used in tests.

_after_cleanup_count =

Undocumented

_cache: dict =

Undocumented

_least_recently_used =

Undocumented

_max_cache =

Undocumented

_most_recently_used =

Undocumented