Skip to content

Fix async caching of None return values#26

Merged
toloco merged 1 commit into
masterfrom
async-single-flight
Apr 8, 2026
Merged

Fix async caching of None return values#26
toloco merged 1 commit into
masterfrom
async-single-flight

Conversation

@toloco
Copy link
Copy Markdown
Owner

@toloco toloco commented Apr 8, 2026

Summary

  • Added _probe(*args, **kwargs) -> (bool, value) to both CachedFunction and SharedCachedFunction in Rust — returns (True, value) on hit, (False, None) on miss
  • AsyncCachedFunction now uses _probe() instead of get(), correctly distinguishing cached None from a cache miss
  • get() unchanged for backwards compatibility

Previously, async-wrapped functions returning None were never cached because get() returns None for both "miss" and "cached None" (PyO3's Option<Py<PyAny>> conflates them).

Test plan

  • test_async_none_return_value — memory backend, assert call_count == 1 after two calls
  • test_async_none_return_value_shared — shared backend, same assertion
  • All existing tests (79 total) pass
  • No regression in benchmarks

🤖 Generated with Claude Code

Added _probe() method to both CachedFunction and SharedCachedFunction
that returns (hit: bool, value) instead of Option — distinguishes
cached None from cache miss. AsyncCachedFunction now uses _probe()
instead of get(), fixing the bug where functions returning None were
never cached on the async path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@toloco toloco force-pushed the async-single-flight branch from 503a677 to 6743551 Compare April 8, 2026 12:36
@toloco toloco merged commit 04aeee4 into master Apr 8, 2026
15 checks passed
@toloco toloco deleted the async-single-flight branch April 8, 2026 12:39
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.

1 participant