-
Notifications
You must be signed in to change notification settings - Fork 0
bug: async cached functions use ainvalidate_cache() not cache_clear() #76
Copy link
Copy link
Open
Description
Description
The API for clearing cache on async decorated functions is inconsistent with sync functions.
Evidence
# Sync — cache_clear() works
@cache(backend=None, ttl=300)
def sync_fn(x): return x * 2
sync_fn.cache_clear() # ✓
# Async — cache_clear() raises TypeError, must use ainvalidate_cache()
@cache(backend=None, ttl=300)
async def async_fn(x): return x * 2
async_fn.cache_clear() # TypeError
await async_fn.ainvalidate_cache() # ✓ (must be awaited)Impact
- Inconsistent API surface between sync and async decorators
- Users expect
cache_clear()to work on all decorated functions (it's stdlib convention fromlru_cache) - Not documented anywhere
Suggested Fix
Either:
- Make
cache_clear()work synchronously on async functions too (preferred — matches lru_cache convention) - Or document the
ainvalidate_cache()requirement prominently in API reference and getting-started
Found by: tests/competitive/test_head_to_head.py::TestAsyncSupport
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels