Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 27, 2026

Plan for Adding Asyncio Support to Cachier

  • 1. Create async variants of helper functions (_calc_entry_async, _function_thread_async)
  • 2. Add async detection logic in the decorator to check if wrapped function is a coroutine
  • 3. Create async wrapper path in the decorator that handles async functions
  • 4. Ensure cores work with both sync and async (storage layer is agnostic)
  • 5. Add comprehensive tests for async functionality with different backends
  • 6. Fix async concurrent call handling (no blocking wait)
  • 7. Create and test async example demonstrating functionality
  • 8. Run existing tests to ensure backward compatibility
  • 9. Run linting and type checking (all passing)
  • 10. Request code review and address feedback
  • 11. Run security checks (0 alerts)
  • 12. Address PR review feedback

✅ All Tasks Complete

PR Review Feedback Addressed:

  1. Fixed test assertions (comments 2731280887, 2731280912, 2731280933):

    • Replaced redundant assertions with call_count_before pattern
    • Now explicitly verifies cache usage by comparing before/after counts
  2. Added allow_none test (comment 2731280841):

    • New test test_async_allow_none covers both allow_none=False (default) and allow_none=True
    • Verifies None values are handled correctly in async path
  3. Fixed BaseException handling (comment 2731280957):

    • Changed from BaseException to Exception in _function_thread_async
    • Avoids catching system exits and keyboard interrupts
  4. Fixed division by zero (comment 2731280814):

    • Added guard in both locations in async_example.py
    • Prevents ZeroDivisionError on very fast systems
  5. Documented async limitations (comment 2731280857):

    • Added clear comment in _call_async explaining wait_for_calc_timeout is not honored
    • Explains why: avoids event loop blocking and maintains async efficiency

Testing Results

  • ✅ All 12 async tests passing (11 original + 1 new allow_none test)
  • ✅ Linting: 0 errors (ruff)
  • ✅ Example runs successfully with all fixes

The implementation is now production-ready with all review feedback addressed!

Original prompt

This section details on the original issue you should resolve

<issue_title>Support for coroutines (asyncio)</issue_title>
<issue_description>Hello,

I was trying to use cachier for caching the result of functions, in particular, HTTP requests.

I am using asyncio throughout my code. I noticed that cachier is fully synchronous, as seen here when calling _calc_entry.

It would be great to have support for caching result of coroutines, using await.

Maybe an async PickeCore / decorator? I am not clear on the best way to accomplish this with minimal code duplication, though.</issue_description>

Comments on the Issue (you are @copilot in this section)

@shaypal5 Hey,

That's an interesting use case. Yeah, I'm not sure myself. I think duplicating the decorator in a way that is agnostic to the core being used would be best, but this might also require rewriting the cores themselves to some extent. Also, it might simply be too complicated or plain impossible to have cores support this agnostically, and so each core would perhaps have to have a separate async implementation. But the pickle one is the important one anyway, I think.

I guess you'd have to figure things out a bit more before I can help you with this, as I really don't have the time to dive into this problem myself.</comment_new>
<comment_new>@shaypal5
I'll try to take a look at this in the coming weeks. This is a good time for this, since many new features are being introduced (now with AI increasing my coding output significantly).</comment_new>


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits January 27, 2026 07:57
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
Copilot AI changed the title [WIP] Add support for coroutines in cachier for async caching Add asyncio/coroutine support for caching async functions Jan 27, 2026
Copilot AI requested a review from Borda January 27, 2026 08:14
@Borda Borda marked this pull request as ready for review January 27, 2026 13:16
@Borda Borda requested a review from shaypal5 as a code owner January 27, 2026 13:16
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.

Support for coroutines (asyncio)

2 participants