class documentation
Method __init__ The default constructor.
Method clear Empty this cache.
Method get Return the element that has been cached for this key.
Method has Return True if an element is cached for the specific key.
Method push Push an element for this key into this cache.
Method remove If an element is cached for key, remove it from the cache.
Instance Variable last_cache the last-access cache
Instance Variable top_cache the top-access cache
Method _on_leave A helper method that will be called whenever any element leaves one of the wrapped chaches.

Inherited from BaseCache:

Instance Variable on_leave a callable expecting two arguments (key, value) that will be called when an element leaves the cache
def __init__(self, on_leave=None, last_cache_size=8, top_cache_size=8):

The default constructor.

Parameters
on_leave:callable or NoneSee BaseCache.__init__
last_cache_size:intsize of the last-access cache
top_cache_size:intsize of the top-access cache
def clear(self, call_on_leave=True):

Empty this cache.

Parameters
call_on_leave:boolif nonzero (default), call BaseCache.on_leave for each element cleared
def get(self, key):

Return the element that has been cached for this key.

Parameters
key:hashablekey for the element that should be returned
Returns
same as passed to BaseCache.pushthe element
Raises
KeyErrorif no element was cached for this key
def has(self, key):

Return True if an element is cached for the specific key.

Parameters
key:hashablekey of element that should be checked
Returns
boolTrue if an element has been cached for this key
def push(self, key, element, allow_replacement=True):

Push an element for this key into this cache.

It is up for the cache to decide whether the element will actually be cached or not. If allow_replacement=False is set, no other element should be kicked from the cache.

Re-pushing an already cached element will not update the cached element.

Parameters
key:hashablekey which will be used to identify the element
element:anyelement to cache
allow_replacement:boolif this value is false, do not cache if this would kick another element from the cache
Returns
boolTrue if the element is now cached, False otherwise
def remove(self, key, call_on_leave=True):

If an element is cached for key, remove it from the cache.

Parameters
key:hashablekey of element to remove
call_on_leave:boolif nonzero (default), call BaseCache.on_leave on the removed element

the last-access cache

the top-access cache

def _on_leave(self, key, value):

A helper method that will be called whenever any element leaves one of the wrapped chaches.

It is used to ensure that even if HybridCache.on_leave is changed after init, the wrapped caches will call the new new function.

Parameters
key:anythe key of the element leaving the cache
value:anyvalue of the element leaving the cache