gcache 2.0.0__tar.gz → 2.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: gcache
3
- Version: 2.0.0
3
+ Version: 2.0.2
4
4
  Summary: Fine grained caching.
5
5
  License: MIT
6
6
  Author: Galileo Technologies Inc.
@@ -35,6 +35,7 @@ Description-Content-Type: text/markdown
35
35
  [![PyPI version](https://badge.fury.io/py/gcache.svg)](https://badge.fury.io/py/gcache)
36
36
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
37
37
  [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
38
+ [![codecov](https://codecov.io/gh/rungalileo/gcache/graph/badge.svg)](https://codecov.io/gh/rungalileo/gcache)
38
39
 
39
40
  A caching library built for moving fast without breaking things. GCache lets you rapidly add new caching use cases while maintaining structure and runtime control guardrails—so you can ramp up gradually, kill a bad cache instantly, and have full observability into what's cached across your system.
40
41
 
@@ -67,6 +68,7 @@ gcache = GCache(GCacheConfig())
67
68
  @gcache.cached(
68
69
  key_type="user_id",
69
70
  id_arg="user_id",
71
+ use_case="GetUser",
70
72
  default_config=GCacheKeyConfig(
71
73
  ttl_sec={CacheLayer.LOCAL: 60, CacheLayer.REMOTE: 300},
72
74
  ramp={CacheLayer.LOCAL: 100, CacheLayer.REMOTE: 100},
@@ -77,7 +79,7 @@ async def get_user(user_id: str) -> dict:
77
79
 
78
80
  # Use it — caching only happens inside enable() blocks
79
81
  with gcache.enable():
80
- user = await get_user("123") # Cached!
82
+ user = await get_user("123") # Cache key: urn:gcache:user_id:123#GetUser
81
83
  ```
82
84
 
83
85
  That's it. The function works normally outside `enable()` blocks, and caches results inside them.
@@ -201,17 +203,49 @@ async def get_user_profile(user_id: str) -> dict:
201
203
 
202
204
  ### Working with Complex Arguments
203
205
 
204
- Real functions have complex arguments. Use `id_arg` tuples and `arg_adapters` to handle them:
206
+ Options for mapping function arguments to cache keys.
207
+
208
+ #### `id_arg` (required)
209
+
210
+ Specifies which argument contains the entity ID for the cache key.
211
+
212
+ **String form** — use when the argument itself is the ID:
213
+ ```python
214
+ id_arg="user_id" # user_id argument is the ID
215
+ ```
216
+
217
+ **Tuple form** — use when the ID needs to be extracted from an object:
218
+ ```python
219
+ id_arg=("user", lambda u: u.id) # Extract ID from User object
220
+ ```
221
+
222
+ #### `arg_adapters`
223
+
224
+ Converts complex arguments to strings for the cache key. Only needed for non-primitive types.
225
+
226
+ ```python
227
+ arg_adapters={
228
+ "filters": lambda f: f.to_cache_key(), # Complex object
229
+ "page": str, # Simple conversion
230
+ }
231
+ ```
232
+
233
+ #### `ignore_args`
234
+
235
+ Excludes arguments that don't affect the cached result.
236
+
237
+ ```python
238
+ ignore_args=["db_session", "logger"]
239
+ ```
240
+
241
+ #### Example
205
242
 
206
243
  ```python
207
244
  @gcache.cached(
208
245
  key_type="user_id",
209
- id_arg=("user", lambda u: u.id), # Extract ID from User object
210
- arg_adapters={
211
- "filters": lambda f: f.to_cache_key(), # Convert complex objects
212
- "page": str, # Simple conversion
213
- },
214
- ignore_args=["db_session", "logger"], # Don't include these in cache key
246
+ id_arg=("user", lambda u: u.id),
247
+ arg_adapters={"filters": lambda f: f.to_cache_key()},
248
+ ignore_args=["db_session", "logger"],
215
249
  )
216
250
  async def search_user_posts(
217
251
  user: User,
@@ -221,8 +255,12 @@ async def search_user_posts(
221
255
  logger: Logger,
222
256
  ) -> list[Post]:
223
257
  ...
258
+
259
+ # Cache key: urn:gcache:user_id:123?filters=active&page=2#SearchUserPosts
224
260
  ```
225
261
 
262
+ The `id_arg` becomes `:123`, `arg_adapters` produce `?filters=active&page=2`, and `ignore_args` are excluded.
263
+
226
264
  ### Sync Functions Work Too
227
265
 
228
266
  ```python
@@ -3,6 +3,7 @@
3
3
  [![PyPI version](https://badge.fury.io/py/gcache.svg)](https://badge.fury.io/py/gcache)
4
4
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
5
  [![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
6
+ [![codecov](https://codecov.io/gh/rungalileo/gcache/graph/badge.svg)](https://codecov.io/gh/rungalileo/gcache)
6
7
 
7
8
  A caching library built for moving fast without breaking things. GCache lets you rapidly add new caching use cases while maintaining structure and runtime control guardrails—so you can ramp up gradually, kill a bad cache instantly, and have full observability into what's cached across your system.
8
9
 
@@ -35,6 +36,7 @@ gcache = GCache(GCacheConfig())
35
36
  @gcache.cached(
36
37
  key_type="user_id",
37
38
  id_arg="user_id",
39
+ use_case="GetUser",
38
40
  default_config=GCacheKeyConfig(
39
41
  ttl_sec={CacheLayer.LOCAL: 60, CacheLayer.REMOTE: 300},
40
42
  ramp={CacheLayer.LOCAL: 100, CacheLayer.REMOTE: 100},
@@ -45,7 +47,7 @@ async def get_user(user_id: str) -> dict:
45
47
 
46
48
  # Use it — caching only happens inside enable() blocks
47
49
  with gcache.enable():
48
- user = await get_user("123") # Cached!
50
+ user = await get_user("123") # Cache key: urn:gcache:user_id:123#GetUser
49
51
  ```
50
52
 
51
53
  That's it. The function works normally outside `enable()` blocks, and caches results inside them.
@@ -169,17 +171,49 @@ async def get_user_profile(user_id: str) -> dict:
169
171
 
170
172
  ### Working with Complex Arguments
171
173
 
172
- Real functions have complex arguments. Use `id_arg` tuples and `arg_adapters` to handle them:
174
+ Options for mapping function arguments to cache keys.
175
+
176
+ #### `id_arg` (required)
177
+
178
+ Specifies which argument contains the entity ID for the cache key.
179
+
180
+ **String form** — use when the argument itself is the ID:
181
+ ```python
182
+ id_arg="user_id" # user_id argument is the ID
183
+ ```
184
+
185
+ **Tuple form** — use when the ID needs to be extracted from an object:
186
+ ```python
187
+ id_arg=("user", lambda u: u.id) # Extract ID from User object
188
+ ```
189
+
190
+ #### `arg_adapters`
191
+
192
+ Converts complex arguments to strings for the cache key. Only needed for non-primitive types.
193
+
194
+ ```python
195
+ arg_adapters={
196
+ "filters": lambda f: f.to_cache_key(), # Complex object
197
+ "page": str, # Simple conversion
198
+ }
199
+ ```
200
+
201
+ #### `ignore_args`
202
+
203
+ Excludes arguments that don't affect the cached result.
204
+
205
+ ```python
206
+ ignore_args=["db_session", "logger"]
207
+ ```
208
+
209
+ #### Example
173
210
 
174
211
  ```python
175
212
  @gcache.cached(
176
213
  key_type="user_id",
177
- id_arg=("user", lambda u: u.id), # Extract ID from User object
178
- arg_adapters={
179
- "filters": lambda f: f.to_cache_key(), # Convert complex objects
180
- "page": str, # Simple conversion
181
- },
182
- ignore_args=["db_session", "logger"], # Don't include these in cache key
214
+ id_arg=("user", lambda u: u.id),
215
+ arg_adapters={"filters": lambda f: f.to_cache_key()},
216
+ ignore_args=["db_session", "logger"],
183
217
  )
184
218
  async def search_user_posts(
185
219
  user: User,
@@ -189,8 +223,12 @@ async def search_user_posts(
189
223
  logger: Logger,
190
224
  ) -> list[Post]:
191
225
  ...
226
+
227
+ # Cache key: urn:gcache:user_id:123?filters=active&page=2#SearchUserPosts
192
228
  ```
193
229
 
230
+ The `id_arg` becomes `:123`, `arg_adapters` produce `?filters=active&page=2`, and `ignore_args` are excluded.
231
+
194
232
  ### Sync Functions Work Too
195
233
 
196
234
  ```python
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "gcache"
3
- version = "2.0.0"
3
+ version = "2.0.2"
4
4
  description = "Fine grained caching."
5
5
  authors = [{ name = "Galileo Technologies Inc.", email = "team@rungalileo.io" }]
6
6
  readme = "README.md"
File without changes
File without changes
File without changes
File without changes