python-redis-cache icon indicating copy to clipboard operation
python-redis-cache copied to clipboard

Decorating async functions?

Open mrisher opened this issue 1 year ago • 4 comments

Hi: This may be simple, but I can't find in the docs or the code: How do I cache the results of an async function? I'm getting an error that a coroutine isn't JSON serializable which is true, but is there a way to tell redis-cache to await instead of caching the coro itself? Or would that be a simple change to submit a PR for?

Thanks much!

mrisher avatar Aug 08 '24 13:08 mrisher

The library currently doesn’t support async. I would be happy to accept a PR for async with tests.

taylorhakes avatar Aug 08 '24 14:08 taylorhakes

Thanks for confirming. Can you give me a hint where we're start for the PR? I will see if I can hack it... (with tests)

Message ID: @.*** com>

mrisher avatar Aug 08 '24 14:08 mrisher

Here is around the line that you would need to change:

https://github.com/taylorhakes/python-redis-cache/blob/master/redis_cache/init.py#L208

Here are some links on what needs to be done:

https://n8henrie.com/2021/11/decorator-to-memoize-sync-or-async-functions-in-python/

https://stackoverflow.com/questions/68410730/how-to-make-decorator-work-with-async-function

taylorhakes avatar Aug 08 '24 15:08 taylorhakes

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Sep 11 '24 01:09 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Oct 01 '24 02:10 github-actions[bot]