Skip to content

Commit 9cc6842

Browse files
committed
change basic usage example a bit
1 parent 574282c commit 9cc6842

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

README.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -91,11 +91,11 @@ memory_cache = EntityCache()
9191
#### With Entity Tracking
9292

9393
```python
94-
# Cache function results and track entity reference *only* for invalidation
95-
@cache.track('user') # Track 'user' entities for targeted invalidation
96-
def get_user(user_id):
97-
# database/interservice query...
98-
# 'id' is default id_key for tracking the 'user' entity
94+
# Cache function results and track entity reference *only* for targeted invalidation
95+
@cache('user') # or `@cache.tracks('user')`
96+
def get_user(user_id):
97+
# db/interservice query...
98+
# 'id' = default id_key of entity
9999
return {"id": user_id, "name": f"User {user_id}"}
100100

101101
# Get user (will be cached)
@@ -105,7 +105,7 @@ user = get_user(42)
105105
@cache.invalidates('user')
106106
def update_users(user_ids, data):
107107
# Update in database...
108-
# The return value is used to extract entity IDs for invalidation of all function calls that this two entities affect
108+
# The return value is used to invalidate all cached functions that was containing this user ids in return
109109
return [{"id": user_ids[0], "name": data.get("name")}, {"id": user_ids[1], "name": data.get("name")}]
110110

111111
# Or manually invalidate
@@ -115,7 +115,6 @@ def delete_user(user_id):
115115
cache.invalidate_entity("user", user_id)
116116
```
117117

118-
You can also use the expressive alias `@cache.tracks('user')` instead of `@cache('user')`.
119118

120119
#### Plain Caching
121120

0 commit comments

Comments
 (0)