Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
jph00 committed Jul 14, 2024
1 parent c2fde43 commit abedf5e
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 22 deletions.
8 changes: 4 additions & 4 deletions fastcore/xtras.py
Original file line number Diff line number Diff line change
Expand Up @@ -686,7 +686,7 @@ def mk_dataclass(cls):
setattr(cls, k, field(default=None))
dataclass(cls, init=True, repr=True, eq=True, order=False, unsafe_hash=False, frozen=False)

# %% ../nbs/03_xtras.ipynb 181
# %% ../nbs/03_xtras.ipynb 179
def flexicache(*funcs, maxsize=128):
"Like `lru_cache`, but customisable with policy `funcs`"
def _f(func):
Expand All @@ -711,23 +711,23 @@ def wrapper(*args, **kwargs):
return wrapper
return _f

# %% ../nbs/03_xtras.ipynb 183
# %% ../nbs/03_xtras.ipynb 181
def time_policy(seconds):
"A `flexicache` policy that expires cached items after `seconds` have passed"
def policy(last_time):
now = time()
return now if last_time is None or now-last_time>seconds else None
return policy

# %% ../nbs/03_xtras.ipynb 184
# %% ../nbs/03_xtras.ipynb 182
def mtime_policy(filepath):
"A `flexicache` policy that expires cached items after `filepath` modified-time changes"
def policy(mtime):
current_mtime = getmtime(filepath)
return current_mtime if mtime is None or current_mtime>mtime else None
return policy

# %% ../nbs/03_xtras.ipynb 187
# %% ../nbs/03_xtras.ipynb 185
def timed_cache(seconds=60, maxsize=128):
"Like `lru_cache`, but also with time-based eviction"
return flexicache(time_policy(seconds), maxsize=maxsize)
18 changes: 0 additions & 18 deletions nbs/03_xtras.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -2840,24 +2840,6 @@
"Person(name=\"Bob\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d = dict(a=1,b=2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"d.popitem()"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down

0 comments on commit abedf5e

Please sign in to comment.