@@ -48,9 +48,9 @@ class _CachierWrappedFunc(Protocol[_P, _R_co]):
4848
4949 def __call__ (self , * args : _P .args , ** kwargs : _P .kwargs ) -> _R_co : ... # pragma: no cover
5050
51- clear_cache : Callable [[] , Any ]
51+ clear_cache : Callable [... , Any ]
5252 clear_being_calculated : Callable [[], Any ]
53- aclear_cache : Callable [[] , Any ]
53+ aclear_cache : Callable [... , Any ]
5454 aclear_being_calculated : Callable [[], Any ]
5555 cache_dpath : Callable [[], Optional [str ]]
5656 precache_value : Callable [..., Any ]
@@ -219,6 +219,13 @@ def _is_async_redis_client(client: Any) -> bool:
219219 return all (inspect .iscoroutinefunction (getattr (client , name , None )) for name in method_names )
220220
221221
222+ def _convert_public_cache_args (func , _is_method : bool , args : tuple , kwds : dict ) -> dict :
223+ """Convert cache-management arguments to canonical cache-key kwargs."""
224+ if _is_method :
225+ args = (None , * args )
226+ return _convert_args_kwargs (func , _is_method = _is_method , args = args , kwds = kwds )
227+
228+
222229def cachier (
223230 hash_func : Optional [HashFunc ] = None ,
224231 hash_params : Optional [HashFunc ] = None ,
@@ -733,9 +740,14 @@ async def func_wrapper(*args: _P.args, **kwargs: _P.kwargs) -> _R:
733740 def func_wrapper (* args : _P .args , ** kwargs : _P .kwargs ) -> _R :
734741 return _call (* args , ** kwargs ) # type: ignore[arg-type]
735742
736- def _clear_cache ():
737- """Clear the cache."""
738- core .clear_cache ()
743+ def _clear_cache (* args , ** kwds ):
744+ """Clear the cache, or only the entry matching the provided arguments."""
745+ if args or kwds :
746+ kwargs = _convert_public_cache_args (func , core .func_is_method , args , kwds )
747+ key = core .get_key ((), kwargs )
748+ core .clear_cache_entry (key )
749+ else :
750+ core .clear_cache ()
739751 if is_coroutine :
740752 return _ImmediateAwaitable ()
741753 return None
@@ -747,9 +759,14 @@ def _clear_being_calculated():
747759 return _ImmediateAwaitable ()
748760 return None
749761
750- async def _aclear_cache ():
751- """Clear the cache asynchronously."""
752- await core .aclear_cache ()
762+ async def _aclear_cache (* args , ** kwds ):
763+ """Clear the cache asynchronously, or only the entry matching the provided arguments."""
764+ if args or kwds :
765+ kwargs = _convert_public_cache_args (func , core .func_is_method , args , kwds )
766+ key = core .get_key ((), kwargs )
767+ await core .aclear_cache_entry (key )
768+ else :
769+ await core .aclear_cache ()
753770
754771 async def _aclear_being_calculated ():
755772 """Mark all entries in this cache as not being calculated asynchronously."""
0 commit comments