fictive.cache.memoize module¶
fictive.cache.memocache
Object wrapper for memoizing using a cache
fictive.cache.memoize¶
-
class
fictive.cache.memoize(*, cache_factory, alias=None, additional_key=None)[source]¶ Decorator that memoizes the decorated
callableusing caches-
__init__(*, cache_factory, alias=None, additional_key=None)[source]¶ - Parameters
cache_factory (callable) – a callable that will return a suitable cache when called with a string key
aliased – a list of parameter names (to the decorated
callable) that will be ignored when generating the unique string key for a memo cache. I.e., calls to the decoratedcallablethat differ only in “aliased” parameters will map to the same cache value. This can be useful for e.g. ignoringself, temporary tokens, or other transient / insignificant parameters when accessing the cache(s).additional_key – a function for furster specifying the cachening key (i.e, used to determine whether to use the memoized value or call the function). MUST take this instance as a first positional argument, the wrapped function as a second positional argument, and then any positional or keyword arguments that will be provided to the decorated function. The callable should return a string-like representation that encapsulates all of the additional attributes that would distinguish cached results. E.g.::
def additional_key(memoize_instance, wrapped_function, *args, **kwargs) -> str
Methods
__init__(*, cache_factory[, alias, …])- param callable cache_factory
get_cache(key)Retrieve the memo cache for
funcbased on thekeymemo_key(func, *args, **kwargs)Generate a hash key using serialized invocation details
Attributes
the methods that will be used to assemble the memoization key
-
__init__(*, cache_factory, alias=None, additional_key=None)[source]¶ - Parameters
cache_factory (callable) – a callable that will return a suitable cache when called with a string key
aliased – a list of parameter names (to the decorated
callable) that will be ignored when generating the unique string key for a memo cache. I.e., calls to the decoratedcallablethat differ only in “aliased” parameters will map to the same cache value. This can be useful for e.g. ignoringself, temporary tokens, or other transient / insignificant parameters when accessing the cache(s).additional_key – a function for furster specifying the cachening key (i.e, used to determine whether to use the memoized value or call the function). MUST take this instance as a first positional argument, the wrapped function as a second positional argument, and then any positional or keyword arguments that will be provided to the decorated function. The callable should return a string-like representation that encapsulates all of the additional attributes that would distinguish cached results. E.g.::
def additional_key(memoize_instance, wrapped_function, *args, **kwargs) -> str
-
-
class
fictive.cache.memoize.MemoizeProxy(wrapped, memoizing_decorator, only=None, exclude=None)[source]¶ Bases:
ObjectProxyAn object proxy wrapper that memoizes an object’s method calls
-
__init__(wrapped, memoizing_decorator, only=None, exclude=None)[source]¶ - Parameters
wrapped – the object that will have its routines memoized
memoizing_decorator – the decorator that will be used to memoize routines
only – if set, routiens will only be memoized if their name is in
onlyexclude – any routines with thei rname in `exclude will not be memoized
-
-
class
fictive.cache.memoize.memoize(*, cache_factory, alias=None, additional_key=None)[source]¶ Bases:
objectDecorator that memoizes the decorated
callableusing caches-
MEMO_KEY_PARTS= ('_func_memo_key', '_args_memo_key')¶ the methods that will be used to assemble the memoization key
-
__init__(*, cache_factory, alias=None, additional_key=None)[source]¶ - Parameters
cache_factory (callable) – a callable that will return a suitable cache when called with a string key
aliased – a list of parameter names (to the decorated
callable) that will be ignored when generating the unique string key for a memo cache. I.e., calls to the decoratedcallablethat differ only in “aliased” parameters will map to the same cache value. This can be useful for e.g. ignoringself, temporary tokens, or other transient / insignificant parameters when accessing the cache(s).additional_key – a function for furster specifying the cachening key (i.e, used to determine whether to use the memoized value or call the function). MUST take this instance as a first positional argument, the wrapped function as a second positional argument, and then any positional or keyword arguments that will be provided to the decorated function. The callable should return a string-like representation that encapsulates all of the additional attributes that would distinguish cached results. E.g.::
def additional_key(memoize_instance, wrapped_function, *args, **kwargs) -> str
-