Skip to content

Commit 73ff81a

Browse files
author
Roman Kitaev
committed
add .cache_clear() to cached functions
1 parent bbbf743 commit 73ff81a

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

Cargo.lock

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "moka-py"
3-
version = "0.1.6"
3+
version = "0.1.7"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

moka_py/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def inner(*args, **kwargs):
3131
cache.set(key, value)
3232
return value
3333

34+
inner.cache_clear = cache.clear
3435
return inner
3536

3637
return dec

tests/test_decorator.py

+15
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,18 @@ async def f(x: int, y: int) -> float:
6363
# A call with the same arguments occurs only once
6464
assert len(lst) == len(cases)
6565
print(lst, answers)
66+
67+
68+
def test_cache_clear():
69+
calls = []
70+
71+
@moka_py.cached()
72+
def f(x: int, y: int) -> float:
73+
calls.append((x, y))
74+
return x / y
75+
76+
f(1, 2)
77+
f(1, 2)
78+
f.cache_clear()
79+
f(1, 2)
80+
assert len(calls) == 2

0 commit comments

Comments
 (0)