Skip to content

bug: async cached functions use ainvalidate_cache() not cache_clear() #76

@27Bslash6

Description

@27Bslash6

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 from lru_cache)
  • Not documented anywhere

Suggested Fix

Either:

  1. Make cache_clear() work synchronously on async functions too (preferred — matches lru_cache convention)
  2. Or document the ainvalidate_cache() requirement prominently in API reference and getting-started

Found by: tests/competitive/test_head_to_head.py::TestAsyncSupport

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions