key_add_prefix¶
-
classmethod
CacheManagerMixin.
key_add_prefix
(key: Union[str, Callable[[Any], str]], auto_prefix: bool = True, _auto_cache=True, call_args: list = None, call_kwargs: dict = None, _lock: Optional[Union[_thread.allocate_lock, Type[privex.helpers.cache.extras.NoLock]]] = None) → str¶ Add this class’s cache key prefix to
key
if it isn’t already prefixed- Parameters
key (str|callable) – The key to prepend the cache key prefix onto - if not already prefixed. This may optionally be a function (e.g. a lambda) which returns a cache key to be auto-prefixed, and any necessary positional/keyword arguments for the function may be specified using the arguments
call_args
andcall_kwargs
auto_prefix (bool) – This argument is mainly used by internal methods to reduce the need to copy/paste handling code which allows users to request that a method does not attempt to auto-prefix the key they entered.
_auto_cache (bool) – This is a boolean key, which controls whether or not keys are automatically logged to the cache key log, which is a list of all known cache keys for a given class. Uses
log_cache_key()
call_args (list) – If
key
is a callable (e.g. a lambda),call_args
can be set to a list of positional arguments to pass to the callable functionkey
call_kwargs (dict) – If
key
is a callable (e.g. a lambda),call_kwargs
can be set to adict
of keyword arguments to pass to the callable functionkey
_lock (ANY_LCK) – This method itself does not use a lock, but it calls upon
log_cache_key()
which does use a lock. You may optionally pass aLock
instance if needed, e.g. to prevent a conflict where the calling function/method has already acquired the class-level lock. It can also be set to the dummy typeNO_LOCK
NO_LOCK
to prevent using a lock.
- Return str new_key
The original
key
after it may or may not have had a prefix prepended to it.