Skip to content

Commit c37500d

Browse files
committed
fixes
1 parent 1205a68 commit c37500d

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/cachier/core.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
from collections import OrderedDict
1414
from concurrent.futures import ThreadPoolExecutor
1515
from datetime import datetime, timedelta
16-
from functools import partial, wraps
16+
from functools import wraps
1717
from typing import Any, Callable, Optional, Union
1818
from warnings import warn
1919

@@ -238,10 +238,9 @@ def _cachier_decorator(func):
238238
# and 'max_age' (if provided).
239239
# This ensures that the strictest freshness requirement is enforced.
240240
#
241-
# The main function wrapper is created using
242-
# partial(_call, timedelta.max), so that by default, max_age is
243-
# effectively infinite (i.e., only 'stale_after' is considered
244-
# unless overridden).
241+
# The main function wrapper is a standard function that passes
242+
# *args and **kwargs to _call. By default, max_age is None,
243+
# so only 'stale_after' is considered unless overridden.
245244
#
246245
# The user-facing API exposes:
247246
# - Per-call: myfunc(..., max_age=timedelta(...))

tests/test_call_with_freshness_threshold.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55

66

77
def test_call_with_freshness_threshold():
8-
from datetime import datetime
9-
108
@cachier.cachier()
119
def test_func(a, b):
1210
return a + b
@@ -20,7 +18,7 @@ def test_func(a, b):
2018
# Wait for cache to become stale
2119
time.sleep(1.0)
2220
# Should trigger recalculation (stale)
23-
val3 = test_func(1, 2, max_age=0.5)
21+
val3 = test_func(1, 2, max_age=timedelta(seconds=0.5))
2422
assert val3 == 3
2523

2624

@@ -57,7 +55,7 @@ def f(x):
5755
assert v1 == v2
5856
time.sleep(1.1)
5957
v3 = f(1, max_age=timedelta(seconds=5))
60-
assert v3 == v1 # max_age looser, cache still valid
58+
assert v3 != v1 # max_age looser, but stale_after still applies (stricter)
6159

6260

6361
def test_max_age_none_defaults_to_stale_after():
@@ -119,5 +117,6 @@ def f(x):
119117
v1 = f(1)
120118
time.sleep(1.1)
121119
v2 = f(1, max_age=timedelta(seconds=0.5))
122-
# With next_time=True, should return stale value (v1), not recalc immediately
120+
# With next_time=True, should return stale value (v1) while
121+
# triggering a recalculation in the background
123122
assert v2 == v1

0 commit comments

Comments
 (0)