-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path6_cache_busting.py
More file actions
29 lines (22 loc) · 829 Bytes
/
6_cache_busting.py
File metadata and controls
29 lines (22 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
import requests
from chalk import realtime
from chalk.client import ChalkClient
from chalk.features import feature, features
@features
class User:
id: int
name: str
fico_score: int = feature(max_staleness="30d")
@realtime
def get_fico_score(name: User.name) -> User.fico_score:
return requests.get("https://experian.com").json()["score"]
if __name__ == "__main__":
# You can force cache invalidation by specifying a
# maximum staleness of 0 seconds at the time of making the query:
ChalkClient().query(
input={User.id: 1, User.name: "Katherine Johnson"},
output=[User.fico_score],
# Cache busting is a special case of providing an override
# max-staleness. See `4_override_max_staleness.py` for more information.
staleness={User.fico_score: "0s"},
)