redis_func_cache.policies.abstract module#
- class redis_func_cache.policies.abstract.AbstractPolicy[source]#
Bases:
ABCAbstract base class for cache eviction policies used by
RedisFuncCache.- Subclasses MUST implement:
- Optionally, subclasses may define:
__key__: A string component used in Redis key naming.
__scripts__: A tuple of two Lua script filenames (get, put).
The use of
__key__or__scripts__depends on the implementation ofcalc_keys()andcalc_hash().- Parameters:
cache – Optional weakref proxy to the
RedisFuncCacheinstance using this policy.
Note
The cache argument may be omitted when instantiating a policy. The RedisFuncCache will bind itself to the policy instance by setting this attribute to a weakref proxy during cache construction.
- async aget_size()[source]#
Asynchronously get the number of items in the cache.
- Return type:
- Returns:
The cache size.
- Raises:
NotImplementedError – If not implemented by subclass.
- async apurge()[source]#
Asynchronously purge the cache.
- Return type:
- Returns:
Number of items removed (if implemented).
- Raises:
NotImplementedError – If not implemented by subclass.
- property cache: CallableProxyType[RedisFuncCache]#
Returns: The
RedisFuncCacheinstance (via weakref proxy) that uses this policy.
- calc_ext_args(f=None, args=None, kwds=None)[source]#
Optionally calculate extra arguments to pass to the Lua script.
- abstractmethod calc_hash(f=None, args=None, kwds=None)[source]#
Calculate a unique hash for the function and its arguments.
- abstractmethod calc_keys(f=None, args=None, kwds=None)[source]#
Calculate the Redis key pair for caching.
- get_size()[source]#
Get the number of items in the cache.
- Return type:
- Returns:
The cache size.
- Raises:
NotImplementedError – If not implemented by subclass.
- property lua_scripts: tuple[Script, Script] | tuple[AsyncScript, AsyncScript]#
Register and return Lua scripts as Redis Script/AsyncScript objects.
- Returns:
Tuple of registered Script or AsyncScript objects.
- purge()[source]#
Purge the cache.
- Return type:
- Returns:
Number of items removed (if implemented).
- Raises:
NotImplementedError – If not implemented by subclass.
- read_lua_scripts()[source]#
Read and clean the Lua scripts from package resources.
- Return type:
tuple[bytes|str|memoryview,bytes|str|memoryview]- Returns:
Tuple of cleaned Lua script texts (get, put).