vinegar.utils.cache¶
Caching utilities.
This module provides various Cache implementations that can be used to store
data that might be reused, while limiting the max. amount of memory that may be
consumed.
For a cache implementation implementing the LRU strategy, see LRUCache.
-
class
vinegar.utils.cache.Cache(*args, **kwds)¶ Interface for cache implementations
This interface is similar to a
MutableMapping, but it does not provide an iterator and it does not provide the methodskeys(),items(),setdefault(...),update(...), andvalues(). It does not support comparison either.In addition to that, code using a cache should not assume that accessing a key (be it by subscripts or through the
getmethod) is a read-only operation, because the cache might internally keep track of which key has been accessed last.An obvious difference to regular mappings is that a cache is typically limited in size, so inserting a new key might have the side effect of removing another one.
-
abstract
clear() → None¶ Clear cache (remove all items).
-
get(key: KeyType, default: ValueType = None) → ValueType¶ Return the item for the specified
keyordefaultif the key is not stored in this cache.- Parameters
key – key that identifies the entry in this cache.
default – default value that is returned if the key is not found.
- Returns
value for
keyordefaultifkeyis not found.
-
abstract
-
class
vinegar.utils.cache.LRUCache(*args, **kwds)¶ Cache using the last recently used (LRU) strategy.
This cache implementation is not thread-safe. If it is supposed to be used from multiple threads, wrap it in a
SynchronizedCache.-
clear() → None¶ Clear cache (remove all items).
-