Skip to content

Commit ee22fa1

Browse files
committed
some renaming
1 parent 23a8146 commit ee22fa1

5 files changed

Lines changed: 19 additions & 8 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,3 +106,5 @@ Pipfile.lock
106106
.DS_Store
107107

108108
tags
109+
110+
.cursor

README.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ Features
5151
* Local caching using pickle files.
5252
* Cross-machine caching using MongoDB.
5353
* Thread-safety.
54-
* **Per-call freshness threshold:** Specify a maximum age for cached values per call.
54+
* **Per-call max age:** Specify a maximum age for cached values per call.
5555

5656
Cachier is **NOT**:
5757

@@ -234,7 +234,7 @@ Per-function call arguments
234234

235235
Cachier also accepts several keyword arguments in the calls of the function it wraps rather than in the decorator call, allowing you to modify its behaviour for a specific function call.
236236

237-
**Freshness Threshold (max_age)**
237+
**Max Age (max_age)**
238238
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
239239
You can specify a maximum allowed age for a cached value on a per-call basis using the `max_age` keyword argument. If the cached value is older than this threshold, a recalculation is triggered. This is in addition to the `stale_after` parameter set at the decorator level; the strictest (smallest) threshold is enforced.
240240

@@ -247,11 +247,11 @@ You can specify a maximum allowed age for a cached value on a per-call basis usi
247247
def add(a, b):
248248
return a + b
249249
250-
# Use a per-call freshness threshold:
250+
# Use a per-call max age:
251251
result = add(1, 2, max_age=timedelta(seconds=10)) # Only use cache if value is <10s old
252252
253253
**How it works:**
254-
- The effective freshness threshold is the minimum of `stale_after` (from the decorator) and `max_age` (from the call).
254+
- The effective max age threshold is the minimum of `stale_after` (from the decorator) and `max_age` (from the call).
255255
- If the cached value is older than this threshold, a new calculation is triggered and the cache is updated.
256256
- If not, the cached value is returned as usual.
257257

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ markers = [
172172
"memory: test the memory core",
173173
"pickle: test the pickle core",
174174
"sql: test the SQL core",
175+
"maxage: test the max_age functionality",
175176
]
176177

177178
# --- coverage ---

src/cachier/core.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def _cachier_decorator(func):
237237
#
238238
# The effective staleness threshold is the minimum of 'stale_after'
239239
# and 'max_age' (if provided).
240-
# This ensures that the strictest freshness requirement is enforced.
240+
# This ensures that the strictest max age requirement is enforced.
241241
#
242242
# The main function wrapper is a standard function that passes
243243
# *args and **kwargs to _call. By default, max_age is None,
@@ -247,7 +247,7 @@ def _cachier_decorator(func):
247247
# - Per-call: myfunc(..., max_age=timedelta(...))
248248
#
249249
# This design allows both one-off (per-call) and default
250-
# (per-decorator) freshness constraints.
250+
# (per-decorator) max age constraints.
251251
# ---
252252

253253
def _call(*args, max_age: Optional[timedelta] = None, **kwds):

tests/test_call_with_freshness_threshold.py renamed to tests/test_call_with_max_age.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import time
22
from datetime import timedelta
33

4+
import pytest
45
import cachier
56

67

7-
def test_call_with_freshness_threshold():
8+
@pytest.mark.maxage
9+
def test_call_with_max_age():
810
@cachier.cachier()
911
def test_func(a, b):
1012
return a + b
@@ -22,6 +24,7 @@ def test_func(a, b):
2224
assert val3 == 3
2325

2426

27+
@pytest.mark.maxage
2528
def test_max_age_stricter_than_stale_after():
2629
import time
2730

@@ -40,6 +43,7 @@ def f(x):
4043
assert v3 != v1 # max_age stricter, triggers recalc
4144

4245

46+
@pytest.mark.maxage
4347
def test_max_age_looser_than_stale_after():
4448
import time
4549

@@ -58,6 +62,7 @@ def f(x):
5862
assert v3 != v1 # max_age looser, but stale_after still applies (stricter)
5963

6064

65+
@pytest.mark.maxage
6166
def test_max_age_none_defaults_to_stale_after():
6267
import time
6368

@@ -74,6 +79,7 @@ def f(x):
7479
assert v2 != v1 # Should trigger recalc (stale_after applies)
7580

7681

82+
@pytest.mark.maxage
7783
def test_negative_max_age_triggers_recalc():
7884
import time
7985

@@ -89,6 +95,7 @@ def f(x):
8995
assert v2 != v1 # Negative max_age always triggers recalc
9096

9197

98+
@pytest.mark.maxage
9299
def test_max_age_zero():
93100
import time
94101

@@ -106,6 +113,7 @@ def f(x):
106113
assert v2 != v1 # Zero max_age always triggers recalc
107114

108115

116+
@pytest.mark.maxage
109117
def test_max_age_with_next_time():
110118
import time
111119

@@ -121,4 +129,4 @@ def f(x):
121129
v2 = f(1, max_age=timedelta(seconds=0.5))
122130
# With next_time=True, should return stale value (v1) while
123131
# triggering a recalculation in the background
124-
assert v2 == v1
132+
assert v2 == v1

0 commit comments

Comments
 (0)