File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed
Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -345,25 +345,25 @@ def cached_function():
345345import time
346346from cachekit import cache
347347
348- @cache (ttl = 60 )
348+ @cache (ttl = 60 , backend = None ) # L1-only (no Redis needed )
349349def test_function (value ):
350- time.sleep(1 ) # Simulate expensive operation
350+ time.sleep(0. 1 ) # Simulate expensive operation
351351 return f " processed_ { value} "
352352
353- # First call - should take ~1 second
353+ # First call - executes function
354354start = time.time()
355355result1 = test_function(" test" )
356356duration1 = time.time() - start
357357print (f " First call: { duration1:.3f } s, Result: { result1} " )
358358
359- # Second call - should be nearly instant
359+ # Second call - L1 cache hit
360360start = time.time()
361361result2 = test_function(" test" )
362362duration2 = time.time() - start
363363print (f " Second call: { duration2:.3f } s, Result: { result2} " )
364364
365365assert result1 == result2
366- assert duration2 < 0.1 # Cache hit should be <100ms (generous for CI)
366+ assert duration2 < duration1 / 2 # Cache hit should be much faster
367367print (" Caching working correctly!" )
368368```
369369
You can’t perform that action at this time.
0 commit comments