Skip to content

Commit c81f4a9

Browse files
CopilotBorda
andcommitted
Remove unreachable async code path for stale entry processing
- Removed lines 475-483 that checked entry._processing with next_time=True - This code path was unreachable in async because mark_entry_being_calculated/mark_entry_not_calculated are called immediately in sequence - The window for entry._processing=True was too brief to be hit by concurrent calls - Simplified async path now only has two cases: next_time=True (return stale + background update) or next_time=False (recalculate and wait) - Updated test docstring to reflect what's actually being tested (concurrent calls with stale cache) - All 30 tests still passing Co-authored-by: Borda <6035284+Borda@users.noreply.github.com>
1 parent 6be5c10 commit c81f4a9

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

src/cachier/core.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -472,15 +472,6 @@ async def _call_async(*args, max_age: Optional[timedelta] = None, **kwds):
472472
_print("And it is fresh!")
473473
return entry.value
474474
_print("But it is stale... :(")
475-
if entry._processing:
476-
if _next_time:
477-
_print("Returning stale.")
478-
return entry.value # return stale val
479-
_print("Already calc. Recalculating (async - no wait).")
480-
# For async, don't wait - just recalculate
481-
# This avoids blocking the event loop
482-
result = await _calc_entry_async(core, key, func, args, kwds, _print)
483-
return result
484475
if _next_time:
485476
_print("Async calc and return stale")
486477
# Mark entry as being calculated then immediately unmark

tests/test_async_core.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -560,10 +560,10 @@ async def async_func(x):
560560
@pytest.mark.asyncio
561561
async def test_stale_entry_being_processed_with_next_time(self):
562562
"""
563-
Test stale entry being processed returns stale value with next_time=True.
563+
Test concurrent calls with stale cache and next_time=True return stale values.
564564
565-
This tests the code path where entry._processing is True and next_time=True,
566-
causing the function to return the stale cached value instead of waiting.
565+
When cache is stale and next_time=True, concurrent calls should return
566+
the stale value while background recalculation happens.
567567
"""
568568
call_count = 0
569569

0 commit comments

Comments
 (0)