Skip to content

Fix: add async support to memoize decorator (#356)#358

Open
Kitan-Dara06 wants to merge 1 commit intograntjenks:masterfrom
Kitan-Dara06:fix-async-memoize
Open

Fix: add async support to memoize decorator (#356)#358
Kitan-Dara06 wants to merge 1 commit intograntjenks:masterfrom
Kitan-Dara06:fix-async-memoize

Conversation

@Kitan-Dara06
Copy link

This PR adds asyncio.iscoroutinefunction support to the memoize decorator. Previously, attempting to memoize an async function would result in caching the raw coroutine object and throwing a TypeError: cannot pickle 'coroutine' object.

By checking if the target is a coroutine, we can properly await the result before saving it to the SQLite database. This allows diskcache to be used natively with async frameworks like FastAPI.

Related Issue:
Fixes #356

Testing:

[x] Reproduced the async caching bug locally.

[x] Verified the fix resolves the TypeError.

[x] Passed 251/251 local pytest suite tests (verified no regressions for synchronous functions).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

sugguest @cache.memoize support async function

1 participant