@@ -87,10 +87,11 @@ async def async_func(x):
8787 assert result1 == 10
8888 assert call_count == 1
8989
90- # Second call - should use cache
90+ # Second call - should use cache (no additional call)
91+ call_count_before = call_count
9192 result2 = await async_func (5 )
9293 assert result2 == 10
93- assert call_count == 1
94+ assert call_count == call_count_before # Verify cache was used
9495
9596 # Wait for cache to become stale
9697 await asyncio .sleep (1.5 )
@@ -127,10 +128,11 @@ async def async_func(x):
127128 assert result1 == 10
128129 assert call_count == 1
129130
130- # Second call - should use cache
131+ # Second call - should use cache (no additional call)
132+ call_count_before = call_count
131133 result2 = await async_func (5 )
132134 assert result2 == 10
133- assert call_count == 1
135+ assert call_count == call_count_before # Verify cache was used
134136
135137 # Wait for cache to become stale
136138 await asyncio .sleep (1.5 )
@@ -329,10 +331,11 @@ async def async_func(x):
329331 assert result1 == 10
330332 assert call_count == 1
331333
332- # Second call - should use cache
334+ # Second call - should use cache (no additional call)
335+ call_count_before = call_count
333336 result2 = await async_func (5 )
334337 assert result2 == 10
335- assert call_count == 1
338+ assert call_count == call_count_before # Verify cache was used
336339
337340 # Wait a bit
338341 await asyncio .sleep (0.5 )
@@ -391,3 +394,68 @@ async def async_func(x):
391394 assert call_count == 0 # No new calls, all from cache
392395
393396 async_func .clear_cache ()
397+
398+
399+ # Test async with allow_none parameter
400+ @pytest .mark .memory
401+ @pytest .mark .asyncio
402+ async def test_async_allow_none ():
403+ """Test async caching with allow_none parameter."""
404+ call_count = 0
405+
406+ # Test with allow_none=False (default)
407+ @cachier (backend = "memory" )
408+ async def async_func_no_none (x ):
409+ nonlocal call_count
410+ call_count += 1
411+ await asyncio .sleep (0.1 )
412+ return None if x == 0 else x * 2
413+
414+ async_func_no_none .clear_cache ()
415+ call_count = 0
416+
417+ # First call returning None - should not be cached
418+ result1 = await async_func_no_none (0 )
419+ assert result1 is None
420+ assert call_count == 1
421+
422+ # Second call with same args - should recalculate (None not cached)
423+ result2 = await async_func_no_none (0 )
424+ assert result2 is None
425+ assert call_count == 2
426+
427+ # Call with non-None result - should be cached
428+ result3 = await async_func_no_none (5 )
429+ assert result3 == 10
430+ assert call_count == 3
431+
432+ # Call again - should use cache
433+ result4 = await async_func_no_none (5 )
434+ assert result4 == 10
435+ assert call_count == 3 # No additional call
436+
437+ async_func_no_none .clear_cache ()
438+
439+ # Test with allow_none=True
440+ call_count = 0
441+
442+ @cachier (backend = "memory" , allow_none = True )
443+ async def async_func_with_none (x ):
444+ nonlocal call_count
445+ call_count += 1
446+ await asyncio .sleep (0.1 )
447+ return None if x == 0 else x * 2
448+
449+ async_func_with_none .clear_cache ()
450+
451+ # First call returning None - should be cached
452+ result1 = await async_func_with_none (0 )
453+ assert result1 is None
454+ assert call_count == 1
455+
456+ # Second call with same args - should use cached None
457+ result2 = await async_func_with_none (0 )
458+ assert result2 is None
459+ assert call_count == 1 # No additional call
460+
461+ async_func_with_none .clear_cache ()
0 commit comments