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.
- {gcache-2.0.0 → gcache-2.0.2}/PKG-INFO +47 -9
- {gcache-2.0.0 → gcache-2.0.2}/README.md +46 -8
- {gcache-2.0.0 → gcache-2.0.2}/pyproject.toml +1 -1
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/__init__.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/__init__.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/cache_interface.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/constants.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/event_loop_thread.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/local_cache.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/metrics.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/noop_cache.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/redis_cache.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/state.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/_internal/wrappers.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/config.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/exceptions.py +0 -0
- {gcache-2.0.0 → gcache-2.0.2}/src/gcache/gcache.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.3
|
|
2
2
|
Name: gcache
|
|
3
|
-
Version: 2.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
|
[](https://badge.fury.io/py/gcache)
|
|
36
36
|
[](https://opensource.org/licenses/MIT)
|
|
37
37
|
[](https://www.python.org/downloads/)
|
|
38
|
+
[](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") #
|
|
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
|
-
|
|
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),
|
|
210
|
-
arg_adapters={
|
|
211
|
-
|
|
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
|
[](https://badge.fury.io/py/gcache)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
[](https://www.python.org/downloads/)
|
|
6
|
+
[](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") #
|
|
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
|
-
|
|
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),
|
|
178
|
-
arg_adapters={
|
|
179
|
-
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|