This module provides various caching mechanisms and utilities.
Property which caches the result of the given getter.
Parameters: | doc – Optional docstring which is used instead of the getters docstring. |
---|
Base class for all caches, which is supposed to be used as a mixin.
Returns a decorator which can be used to create functions whose results are cached.
In order to clear the cache of the decorated function call .clear() on it.
@CacheBase.decorate(maxsize=1024) # items stored in the cache
def foo(a, b):
return a + b # imagine a very expensive operation here
OrderedDict based cache which removes the least recently used item once maxsize is reached.
Note
The order of the dict is changed each time you access the dict.
dict based cache which removes the least frequently used item once maxsize is reached.
A memoization decorator, which uses a simple dictionary of infinite size as cache:
@memoize
def foo(a, b):
return a + b
New in version 0.5.