cachu 0.1.1__py3-none-any.whl → 0.1.2__py3-none-any.whl
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.
cachu/__init__.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cachu
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.2
|
|
4
4
|
Summary: Flexible caching library built on dogpile.cache
|
|
5
5
|
Author: bissli
|
|
6
6
|
License-Expression: 0BSD
|
|
@@ -14,6 +14,7 @@ Requires-Dist: redis; extra == "redis"
|
|
|
14
14
|
Provides-Extra: test
|
|
15
15
|
Requires-Dist: pytest; extra == "test"
|
|
16
16
|
Requires-Dist: pytest-mock; extra == "test"
|
|
17
|
+
Requires-Dist: redis; extra == "test"
|
|
17
18
|
Requires-Dist: testcontainers[redis]; extra == "test"
|
|
18
19
|
|
|
19
20
|
# cachu
|
|
@@ -25,13 +26,13 @@ Flexible caching library with support for memory, file, and Redis backends.
|
|
|
25
26
|
**Basic installation:**
|
|
26
27
|
|
|
27
28
|
```bash
|
|
28
|
-
pip install
|
|
29
|
+
pip install cachu
|
|
29
30
|
```
|
|
30
31
|
|
|
31
32
|
**With Redis support:**
|
|
32
33
|
|
|
33
34
|
```bash
|
|
34
|
-
pip install
|
|
35
|
+
pip install cachu[redis]
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
## Quick Start
|
|
@@ -107,7 +108,7 @@ all_configs = cachu.get_all_configs() # All configurations
|
|
|
107
108
|
### Basic Caching
|
|
108
109
|
|
|
109
110
|
```python
|
|
110
|
-
from cachu import
|
|
111
|
+
from cachu import cache
|
|
111
112
|
|
|
112
113
|
@cache(ttl=300, backend='memory')
|
|
113
114
|
def expensive_operation(param: str) -> dict:
|
|
@@ -138,6 +139,8 @@ def fetch_external_data(api_key: str) -> dict:
|
|
|
138
139
|
Tags organize cache entries into logical groups for selective clearing:
|
|
139
140
|
|
|
140
141
|
```python
|
|
142
|
+
from cachu import cache, cache_clear
|
|
143
|
+
|
|
141
144
|
@cache(ttl=300, tag='users')
|
|
142
145
|
def get_user(user_id: int) -> dict:
|
|
143
146
|
return fetch_user(user_id)
|
|
@@ -147,7 +150,7 @@ def get_product(product_id: int) -> dict:
|
|
|
147
150
|
return fetch_product(product_id)
|
|
148
151
|
|
|
149
152
|
# Clear only user caches
|
|
150
|
-
|
|
153
|
+
cache_clear(tag='users', backend='memory', ttl=300)
|
|
151
154
|
```
|
|
152
155
|
|
|
153
156
|
### Conditional Caching
|
|
@@ -214,12 +217,14 @@ result = get_data(123, _overwrite_cache=True)
|
|
|
214
217
|
Track hits and misses:
|
|
215
218
|
|
|
216
219
|
```python
|
|
220
|
+
from cachu import cache, cache_info
|
|
221
|
+
|
|
217
222
|
@cache(ttl=300)
|
|
218
223
|
def get_user(user_id: int) -> dict:
|
|
219
224
|
return fetch_user(user_id)
|
|
220
225
|
|
|
221
226
|
# After some usage
|
|
222
|
-
info =
|
|
227
|
+
info = cache_info(get_user)
|
|
223
228
|
print(f"Hits: {info.hits}, Misses: {info.misses}, Size: {info.currsize}")
|
|
224
229
|
```
|
|
225
230
|
|
|
@@ -267,7 +272,7 @@ cache_delete(get_user, user_id=123)
|
|
|
267
272
|
### Clearing Caches
|
|
268
273
|
|
|
269
274
|
```python
|
|
270
|
-
from cachu import
|
|
275
|
+
from cachu import cache_clear
|
|
271
276
|
|
|
272
277
|
# Clear specific region
|
|
273
278
|
cache_clear(backend='memory', ttl=300)
|
|
@@ -302,7 +307,8 @@ def get_data(id: int) -> dict:
|
|
|
302
307
|
return fetch(id)
|
|
303
308
|
|
|
304
309
|
# In tests/conftest.py
|
|
305
|
-
cachu
|
|
310
|
+
from cachu import cache_clear
|
|
311
|
+
cache_clear(backend='memory', ttl=300, package='myapp')
|
|
306
312
|
```
|
|
307
313
|
|
|
308
314
|
## Instance and Class Methods
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
cachu/__init__.py,sha256=
|
|
1
|
+
cachu/__init__.py,sha256=_-9rrpnkuhyTABEyh7lBRMZNb60AXzm3ZdHjBdaQDKc,676
|
|
2
2
|
cachu/cache.py,sha256=UOh1hsvo5wqpf-quU0glGZi5bgjF8gkaSmYIkAwWfUA,23362
|
|
3
3
|
cachu/config.py,sha256=KtcDGpSTJmjRrcNLz9_Om3O814oJJ3p8gntB84Pd6Dk,5922
|
|
4
4
|
cachu/decorator.py,sha256=FqD-On66WYYIAOWIe-umlILFc8XcuE8IQHTV6MnFA9o,8254
|
|
@@ -9,7 +9,7 @@ cachu/backends/__init__.py,sha256=dM6NfSRXMCOeTg9A9-scgiT_6r_BfzbmT1GVNqL6egU,12
|
|
|
9
9
|
cachu/backends/file.py,sha256=2ssQmqvpLRDLX21joXRZKxfHekjAjb5gd_gHt52SgVA,5313
|
|
10
10
|
cachu/backends/memory.py,sha256=kIgrVU8k_3Aquyj2PDf8IPbTjCITM_0V5GU47m3fJmo,3138
|
|
11
11
|
cachu/backends/redis.py,sha256=yE5rEBgOij9QOeC1VhWdIbGCgi442q-aWfmbbG4aNSE,3858
|
|
12
|
-
cachu-0.1.
|
|
13
|
-
cachu-0.1.
|
|
14
|
-
cachu-0.1.
|
|
15
|
-
cachu-0.1.
|
|
12
|
+
cachu-0.1.2.dist-info/METADATA,sha256=nRI56YIazr3xLkbdGpg9Zq7g46blUpJvYvzBvMGUNN8,9676
|
|
13
|
+
cachu-0.1.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
14
|
+
cachu-0.1.2.dist-info/top_level.txt,sha256=g80nNoMvLMzhSwQWV-JotCBqtsLAHeFMBo_g8hCK8hQ,6
|
|
15
|
+
cachu-0.1.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|