Skip to content

Commit c6fbdcd

Browse files
Bordashaypal5
authored andcommitted
Apply suggestions from code review
1 parent e2aca2d commit c6fbdcd

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

src/cachier/core.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def cachier(
214214
def _cachier_decorator(func):
215215
core.set_func(func)
216216

217-
def _call(max_age: timedelta, *args, **kwds):
217+
def _call(*args, max_age: Optional[timedelta] = None, **kwds):
218218
nonlocal allow_none
219219
_allow_none = _update_with_defaults(allow_none, "allow_none", kwds)
220220
# print('Inside general wrapper for {}.'.format(func.__name__))
@@ -259,7 +259,8 @@ def _call(max_age: timedelta, *args, **kwds):
259259
if _allow_none or entry.value is not None:
260260
_print("Cached result found.")
261261
now = datetime.now()
262-
if now - entry.time <= min(_stale_after, max_age):
262+
stale_delta = min(_stale_after, max_age) if max_age is not None else _stale_after
263+
if now - entry.time <= stale_delta:
263264
_print("And it is fresh!")
264265
return entry.value
265266
_print("But it is stale... :(")

0 commit comments

Comments
 (0)