CacheToolsUtils 10.4__tar.gz → 12.0__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.
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/CacheToolsUtils.egg-info/PKG-INFO +7 -9
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/CacheToolsUtils.egg-info/requires.txt +3 -5
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/CacheToolsUtils.py +131 -100
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/PKG-INFO +7 -9
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/pyproject.toml +7 -4
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/CacheToolsUtils.egg-info/SOURCES.txt +0 -0
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/CacheToolsUtils.egg-info/dependency_links.txt +0 -0
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/CacheToolsUtils.egg-info/top_level.txt +0 -0
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/LICENSE +0 -0
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/MANIFEST.in +0 -0
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/README.md +0 -0
- {cachetoolsutils-10.4 → cachetoolsutils-12.0}/setup.cfg +0 -0
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: CacheToolsUtils
|
|
3
|
-
Version:
|
|
3
|
+
Version: 12.0
|
|
4
4
|
Summary: Cachetools Utilities
|
|
5
5
|
Author-email: Fabien Coelho <cachetools.utils@coelho.net>
|
|
6
|
-
License: CC0
|
|
6
|
+
License-Expression: CC0-1.0
|
|
7
7
|
Project-URL: repository, https://github.com/zx80/cachetools-utils
|
|
8
8
|
Project-URL: documentation, https://zx80.github.io/cachetools-utils/
|
|
9
9
|
Project-URL: issues, https://github.com/zx80/cachetools-utils/issues
|
|
10
10
|
Project-URL: package, https://pypi.org/project/CacheToolsUtils/
|
|
11
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
|
14
13
|
Classifier: Programming Language :: Python
|
|
15
14
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
15
|
Requires-Python: >=3.10
|
|
@@ -27,11 +26,9 @@ Requires-Dist: pytest; extra == "dev"
|
|
|
27
26
|
Requires-Dist: coverage; extra == "dev"
|
|
28
27
|
Requires-Dist: pymarkdownlnt; extra == "dev"
|
|
29
28
|
Provides-Extra: doc
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist:
|
|
32
|
-
Requires-Dist:
|
|
33
|
-
Requires-Dist: sphinx-lint; extra == "doc"
|
|
34
|
-
Requires-Dist: myst_parser; extra == "doc"
|
|
29
|
+
Requires-Dist: mkdocs; extra == "doc"
|
|
30
|
+
Requires-Dist: mkdocs-material; extra == "doc"
|
|
31
|
+
Requires-Dist: mkdocstrings[python]; extra == "doc"
|
|
35
32
|
Provides-Extra: crypt
|
|
36
33
|
Requires-Dist: pycryptodome; extra == "crypt"
|
|
37
34
|
Provides-Extra: tests
|
|
@@ -41,6 +38,7 @@ Provides-Extra: pub
|
|
|
41
38
|
Requires-Dist: build; extra == "pub"
|
|
42
39
|
Requires-Dist: wheel; extra == "pub"
|
|
43
40
|
Requires-Dist: twine; extra == "pub"
|
|
41
|
+
Dynamic: license-file
|
|
44
42
|
|
|
45
43
|
# CacheToolsUtils
|
|
46
44
|
|
|
@@ -5,7 +5,8 @@ CacheTools Utilities. This code is public domain.
|
|
|
5
5
|
# FIXME 3.13t checks without Cipher package
|
|
6
6
|
# pyright: reportMissingImports=false
|
|
7
7
|
|
|
8
|
-
from typing import Any
|
|
8
|
+
from typing import Any
|
|
9
|
+
from collections.abc import Callable, MutableMapping
|
|
9
10
|
import abc
|
|
10
11
|
|
|
11
12
|
import base64
|
|
@@ -27,8 +28,12 @@ log = logging.getLogger(__name__)
|
|
|
27
28
|
_NO_DEFAULT = object()
|
|
28
29
|
|
|
29
30
|
|
|
31
|
+
class CTUError(Exception):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
30
35
|
class _MutMapMix:
|
|
31
|
-
"""Convenient MutableMapping Mixin, forward to _cache
|
|
36
|
+
"""Convenient MutableMapping Mixin, forward to `_cache`."""
|
|
32
37
|
|
|
33
38
|
# FIXME coverage reports this as missing with Python 3.14
|
|
34
39
|
_cache: MutableMapping # pragma: no cover
|
|
@@ -53,7 +58,7 @@ class _MutMapMix:
|
|
|
53
58
|
|
|
54
59
|
|
|
55
60
|
class _KeyMutMapMix(_MutMapMix):
|
|
56
|
-
"""Convenient MutableMapping Mixin with a key filter, forward to _cache
|
|
61
|
+
"""Convenient MutableMapping Mixin with a key filter, forward to `_cache`."""
|
|
57
62
|
|
|
58
63
|
@abc.abstractmethod
|
|
59
64
|
def _key(self, key: Any) -> Any: # pragma: no cover
|
|
@@ -73,7 +78,7 @@ class _KeyMutMapMix(_MutMapMix):
|
|
|
73
78
|
|
|
74
79
|
|
|
75
80
|
class _StatsMix:
|
|
76
|
-
"""Convenient Mixin to forward stats methods to _cache
|
|
81
|
+
"""Convenient Mixin to forward stats methods to `_cache`."""
|
|
77
82
|
|
|
78
83
|
def hits(self) -> float|None:
|
|
79
84
|
return self._cache.hits() # type: ignore
|
|
@@ -114,9 +119,11 @@ class _RedisMix: # pragma: no cover
|
|
|
114
119
|
class DebugCache(_StatsMix, MutableMapping):
|
|
115
120
|
"""Debug class.
|
|
116
121
|
|
|
117
|
-
:
|
|
118
|
-
|
|
119
|
-
|
|
122
|
+
Parameters:
|
|
123
|
+
|
|
124
|
+
- cache: actual cache
|
|
125
|
+
- log: logging instance
|
|
126
|
+
- name: name of instance for output
|
|
120
127
|
"""
|
|
121
128
|
|
|
122
129
|
def __init__(self, cache: MutableMapping, log: logging.Logger, name="cache"):
|
|
@@ -162,10 +169,10 @@ class DebugCache(_StatsMix, MutableMapping):
|
|
|
162
169
|
|
|
163
170
|
|
|
164
171
|
class DictCache(_MutMapMix, MutableMapping):
|
|
165
|
-
"""Cache class based on dict
|
|
172
|
+
"""Cache class based on `dict`."""
|
|
166
173
|
|
|
167
174
|
def __init__(self):
|
|
168
|
-
self._cache =
|
|
175
|
+
self._cache = {}
|
|
169
176
|
|
|
170
177
|
def clear(self):
|
|
171
178
|
self._cache.clear()
|
|
@@ -174,17 +181,19 @@ class DictCache(_MutMapMix, MutableMapping):
|
|
|
174
181
|
class LockedCache(_MutMapMix, _StatsMix, _RedisMix, MutableMapping):
|
|
175
182
|
"""Cache class with a lock.
|
|
176
183
|
|
|
177
|
-
:
|
|
178
|
-
:param lock: lock (context manager) to use
|
|
184
|
+
Parameters:
|
|
179
185
|
|
|
180
|
-
|
|
186
|
+
- cache: actual cache.
|
|
187
|
+
- lock: lock (context manager) to use
|
|
181
188
|
|
|
182
|
-
|
|
189
|
+
The locked layer should be the last one before the actual cache.
|
|
183
190
|
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
191
|
+
```python
|
|
192
|
+
import threading
|
|
193
|
+
import cachetools as ct
|
|
194
|
+
import CacheToolsUtils as ctu
|
|
195
|
+
cache = ctu.LockedCache(ct.LFUCache(), threading.RLock())
|
|
196
|
+
```
|
|
188
197
|
"""
|
|
189
198
|
|
|
190
199
|
def __init__(self, cache: MutableMapping, lock):
|
|
@@ -211,8 +220,10 @@ class LockedCache(_MutMapMix, _StatsMix, _RedisMix, MutableMapping):
|
|
|
211
220
|
class PrefixedCache(_KeyMutMapMix, _StatsMix, MutableMapping):
|
|
212
221
|
"""Cache class to add a key prefix.
|
|
213
222
|
|
|
214
|
-
:
|
|
215
|
-
|
|
223
|
+
Parameters:
|
|
224
|
+
|
|
225
|
+
- cache: actual cache.
|
|
226
|
+
- prefix: prefix to prepend to keys.
|
|
216
227
|
"""
|
|
217
228
|
|
|
218
229
|
def __init__(self, cache: MutableMapping, prefix: str|bytes = ""):
|
|
@@ -232,9 +243,11 @@ class PrefixedCache(_KeyMutMapMix, _StatsMix, MutableMapping):
|
|
|
232
243
|
class AutoPrefixedCache(PrefixedCache):
|
|
233
244
|
"""Cache class with an automatic counter-based string prefix.
|
|
234
245
|
|
|
235
|
-
:
|
|
236
|
-
|
|
237
|
-
|
|
246
|
+
Parameters:
|
|
247
|
+
|
|
248
|
+
- cache: actual cache.
|
|
249
|
+
- sep: prefix separator, default is ".".
|
|
250
|
+
- method: encoding method in "b64", "b64u", "b32", "b32x", "b16",
|
|
238
251
|
"a85" and "b85". Default is "b64".
|
|
239
252
|
"""
|
|
240
253
|
|
|
@@ -253,7 +266,7 @@ class AutoPrefixedCache(PrefixedCache):
|
|
|
253
266
|
|
|
254
267
|
def __init__(self, cache: MutableMapping, sep: str = ".", method: str = "b64"):
|
|
255
268
|
if method not in AutoPrefixedCache._METHODS:
|
|
256
|
-
raise
|
|
269
|
+
raise CTUError(f"invalid conversion method: {method}")
|
|
257
270
|
encoder = AutoPrefixedCache._METHODS[method]
|
|
258
271
|
length = max(1, (AutoPrefixedCache._COUNTER.bit_length() + 7) // 8)
|
|
259
272
|
# NOTE byteorder default added to 3.11
|
|
@@ -265,16 +278,17 @@ class AutoPrefixedCache(PrefixedCache):
|
|
|
265
278
|
class StatsCache(_MutMapMix, MutableMapping):
|
|
266
279
|
"""Cache class to keep stats.
|
|
267
280
|
|
|
268
|
-
:
|
|
281
|
+
Parameter:
|
|
269
282
|
|
|
270
|
-
|
|
283
|
+
- cache: actual cache.
|
|
271
284
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
285
|
+
```python
|
|
286
|
+
import cachetools as ct
|
|
287
|
+
import CacheToolsUtils as ctu
|
|
288
|
+
cache = ctu.StatsCache(ct.LRUCache())
|
|
289
|
+
```
|
|
276
290
|
|
|
277
|
-
Note that CacheTools
|
|
291
|
+
Note that CacheTools `cached` decorator with `info=True` provides
|
|
278
292
|
hits, misses, maxsize and currsize information.
|
|
279
293
|
However, this only works for its own classes.
|
|
280
294
|
"""
|
|
@@ -329,9 +343,11 @@ class StatsCache(_MutMapMix, MutableMapping):
|
|
|
329
343
|
class TwoLevelCache(_MutMapMix, MutableMapping):
|
|
330
344
|
"""Two-Level Cache class for CacheTools.
|
|
331
345
|
|
|
332
|
-
:
|
|
333
|
-
|
|
334
|
-
|
|
346
|
+
Parameters:
|
|
347
|
+
|
|
348
|
+
- cache: first (smaller, shorter TTL) cache
|
|
349
|
+
- cache2: second (larger, longer TTL) cache
|
|
350
|
+
- resilient: whether to ignore cache2 failures
|
|
335
351
|
"""
|
|
336
352
|
|
|
337
353
|
def __init__(self, cache: MutableMapping, cache2: MutableMapping, resilient=False):
|
|
@@ -434,7 +450,7 @@ class _Cipher:
|
|
|
434
450
|
kwargs = {"mode": cipher.MODE_CBC}
|
|
435
451
|
size = 16
|
|
436
452
|
else:
|
|
437
|
-
raise
|
|
453
|
+
raise CTUError(f"unexpected cipher: {name}")
|
|
438
454
|
self._cipher = cipher
|
|
439
455
|
self._params = params
|
|
440
456
|
self._kwargs = kwargs
|
|
@@ -457,10 +473,12 @@ class _Cipher:
|
|
|
457
473
|
class EncryptedCache(_KeyMutMapMix, _StatsMix, MutableMapping):
|
|
458
474
|
"""Encrypted Bytes Key-Value Cache.
|
|
459
475
|
|
|
460
|
-
:
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
476
|
+
Parameters:
|
|
477
|
+
|
|
478
|
+
- secret: bytes of secret, at least 16 bytes.
|
|
479
|
+
- hsize: size of hashed key, default is *16*.
|
|
480
|
+
- csize: value checksum size, default is *0*.
|
|
481
|
+
- cipher: chose cipher from "Salsa20", "AES-128-CBC" or "ChaCha20".
|
|
464
482
|
|
|
465
483
|
The key is *not* encrypted but simply hashed, thus they are
|
|
466
484
|
fixed size with a very low collision probability.
|
|
@@ -553,14 +571,16 @@ class ToBytesCache(_KeyMutMapMix, _StatsMix, MutableMapping):
|
|
|
553
571
|
def cached(cache, *args, **kwargs):
|
|
554
572
|
"""Extended decorator with delete and exists.
|
|
555
573
|
|
|
556
|
-
All parameters are forwarded to
|
|
574
|
+
All parameters are forwarded to `cachetools.cached`.
|
|
557
575
|
|
|
558
|
-
:
|
|
576
|
+
Parameter:
|
|
559
577
|
|
|
560
|
-
|
|
578
|
+
- cache: actual cache.
|
|
561
579
|
|
|
562
|
-
|
|
563
|
-
|
|
580
|
+
If *f(\\*args, \\*\\*kwargs)* is the _cached_ function, then:
|
|
581
|
+
|
|
582
|
+
- `f.cache_in(*args, **kwargs)` tells whether the result is cached.
|
|
583
|
+
- `f.cache_del(*args, **kwargs)` deletes (invalidates) the cached result.
|
|
564
584
|
"""
|
|
565
585
|
|
|
566
586
|
def decorate(fun: Callable):
|
|
@@ -603,15 +623,17 @@ def cacheMethods(
|
|
|
603
623
|
):
|
|
604
624
|
"""Cache some object methods.
|
|
605
625
|
|
|
606
|
-
:
|
|
607
|
-
:param obj: object instance to be cached.
|
|
608
|
-
:param gen: generator of PrefixedCache.
|
|
609
|
-
:param opts: additional parameters when calling `cached`.
|
|
610
|
-
:param funs: name of methods and corresponding prefix
|
|
626
|
+
Parameters:
|
|
611
627
|
|
|
612
|
-
|
|
628
|
+
- cache: cache to use.
|
|
629
|
+
- obj: object instance to be cached.
|
|
630
|
+
- gen: generator of PrefixedCache.
|
|
631
|
+
- opts: additional parameters when calling `cached`.
|
|
632
|
+
- funs: name of methods and corresponding prefix
|
|
613
633
|
|
|
614
|
-
|
|
634
|
+
```python
|
|
635
|
+
cacheMethods(cache, item, PrefixedCache, compute1="c1.", compute2="c2.")
|
|
636
|
+
```
|
|
615
637
|
"""
|
|
616
638
|
for fun, prefix in funs.items():
|
|
617
639
|
assert hasattr(obj, fun), f"cannot cache missing method {fun} on {obj}"
|
|
@@ -630,15 +652,17 @@ def cacheFunctions(
|
|
|
630
652
|
):
|
|
631
653
|
"""Cache some global functions, with a prefix.
|
|
632
654
|
|
|
633
|
-
:
|
|
634
|
-
:param globs: global object dictionary.
|
|
635
|
-
:param gen: generator of PrefixedCache.
|
|
636
|
-
:param opts: additional parameters when calling `cached`.
|
|
637
|
-
:param funs: name of functions and corresponding prefix
|
|
655
|
+
Parameters:
|
|
638
656
|
|
|
639
|
-
|
|
657
|
+
- cache: cache to use.
|
|
658
|
+
- globs: global object dictionary.
|
|
659
|
+
- gen: generator of PrefixedCache.
|
|
660
|
+
- opts: additional parameters when calling `cached`.
|
|
661
|
+
- funs: name of functions and corresponding prefix
|
|
640
662
|
|
|
641
|
-
|
|
663
|
+
```python
|
|
664
|
+
cacheFunctions(cache, globals(), PrefixedCache, fun1="f1.", fun2="f2.")
|
|
665
|
+
```
|
|
642
666
|
"""
|
|
643
667
|
for fun, prefix in funs.items():
|
|
644
668
|
assert fun in globs, "caching functions: {fun} not found"
|
|
@@ -680,7 +704,7 @@ class _HashJsonKey:
|
|
|
680
704
|
return self._key
|
|
681
705
|
|
|
682
706
|
|
|
683
|
-
# NOTE not very useful, behaves as _HashJsonKey.
|
|
707
|
+
# NOTE not very useful, behaves as _HashJsonKey, but is not a class.
|
|
684
708
|
def hash_json_key(*args, **kwargs):
|
|
685
709
|
"""Function handling of above class, to keep it hidden."""
|
|
686
710
|
return _HashJsonKey(*args, **kwargs)
|
|
@@ -697,13 +721,13 @@ def full_hash_key(*args, **kwargs) -> str:
|
|
|
697
721
|
# MEMCACHED
|
|
698
722
|
#
|
|
699
723
|
class JsonSerde:
|
|
700
|
-
"""JSON serialize/deserialize class for MemCached (
|
|
701
|
-
|
|
702
|
-
.. code-block:: python
|
|
724
|
+
"""JSON serialize/deserialize class for MemCached (`pymemcache`).
|
|
703
725
|
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
726
|
+
```python
|
|
727
|
+
import pymemcache as pmc
|
|
728
|
+
import CacheToolsUtils as ctu
|
|
729
|
+
pmc_cache = pmc.Client(server="localhost", serde=ctu.JsonSerde())
|
|
730
|
+
```
|
|
707
731
|
"""
|
|
708
732
|
|
|
709
733
|
# keep strings, else json
|
|
@@ -724,22 +748,25 @@ class JsonSerde:
|
|
|
724
748
|
elif flag == 3:
|
|
725
749
|
return json.loads(value.decode("utf-8"))
|
|
726
750
|
else:
|
|
727
|
-
raise
|
|
751
|
+
raise CTUError(f"Unknown serialization format: {flag}")
|
|
728
752
|
|
|
729
753
|
|
|
730
754
|
class MemCached(_KeyMutMapMix, MutableMapping):
|
|
731
755
|
"""MemCached-compatible wrapper class for cachetools with key encoding.
|
|
732
756
|
|
|
733
|
-
:
|
|
757
|
+
Parameter:
|
|
734
758
|
|
|
735
|
-
|
|
759
|
+
- cache: actual memcached cache.
|
|
736
760
|
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
761
|
+
```python
|
|
762
|
+
import pymemcache as pmc
|
|
763
|
+
import CacheToolsUtils as ctu
|
|
764
|
+
cache = ctu.MemCached(pmc.Client(server="localhost", serde=ctu.JsonSerde()))
|
|
740
765
|
|
|
741
|
-
|
|
742
|
-
|
|
766
|
+
@ctu.cached(cache=cache)
|
|
767
|
+
def whatever(...):
|
|
768
|
+
...
|
|
769
|
+
```
|
|
743
770
|
"""
|
|
744
771
|
|
|
745
772
|
def __init__(self, cache):
|
|
@@ -773,15 +800,17 @@ class MemCached(_KeyMutMapMix, MutableMapping):
|
|
|
773
800
|
class PrefixedMemCached(MemCached):
|
|
774
801
|
"""MemCached-compatible wrapper class for cachetools with a key prefix.
|
|
775
802
|
|
|
776
|
-
:
|
|
777
|
-
:param prefix: post key-encoding prepended prefix.
|
|
803
|
+
Parameters:
|
|
778
804
|
|
|
779
|
-
|
|
805
|
+
- cache: actual memcached cache.
|
|
806
|
+
- prefix: post key-encoding prepended prefix.
|
|
780
807
|
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
808
|
+
```python
|
|
809
|
+
import pymemcache as pmc
|
|
810
|
+
import CacheToolsUtils as ctu
|
|
811
|
+
# add a "app." prefix to keys, after serialization
|
|
812
|
+
cache = ctu.PrefixedMemCached(pmc.Client(server="localhost", serde=ctu.JsonSerde()), "app.")
|
|
813
|
+
```
|
|
785
814
|
"""
|
|
786
815
|
|
|
787
816
|
def __init__(self, cache, prefix: str = ""):
|
|
@@ -796,20 +825,22 @@ class PrefixedMemCached(MemCached):
|
|
|
796
825
|
# REDIS
|
|
797
826
|
#
|
|
798
827
|
class RedisCache(MutableMapping):
|
|
799
|
-
"""Redis TTL-ed wrapper for cachetools (
|
|
828
|
+
"""Redis TTL-ed wrapper for cachetools (`redis`).
|
|
800
829
|
|
|
801
|
-
:
|
|
802
|
-
:param ttl: time-to-live in seconds, used as default expiration (``ex``), default is 600.
|
|
803
|
-
:param raw: whether to serialize keys and values, default is *False*.
|
|
830
|
+
Parameters:
|
|
804
831
|
|
|
805
|
-
|
|
832
|
+
- cache: actual redis cache.
|
|
833
|
+
- ttl: time-to-live in seconds, used as default expiration (`ex`), default is _600_.
|
|
834
|
+
- raw: whether to serialize keys and values, default is *False*.
|
|
806
835
|
|
|
807
|
-
|
|
836
|
+
Keys and values are serialized in *JSON*.
|
|
808
837
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
838
|
+
```python
|
|
839
|
+
import redis
|
|
840
|
+
import CacheToolsUtils as ctu
|
|
841
|
+
# redis with 1 hour expiration
|
|
842
|
+
cache = ctu.RedisCache(redis.Redis(host="localhost"), 3600)
|
|
843
|
+
```
|
|
813
844
|
"""
|
|
814
845
|
|
|
815
846
|
def __init__(self, cache, ttl=600, raw=False):
|
|
@@ -849,7 +880,7 @@ class RedisCache(MutableMapping):
|
|
|
849
880
|
return self._cache.dbsize()
|
|
850
881
|
|
|
851
882
|
def __iter__(self):
|
|
852
|
-
raise
|
|
883
|
+
raise NotImplementedError("not implemented yet")
|
|
853
884
|
|
|
854
885
|
def info(self, *args, **kwargs):
|
|
855
886
|
"""Return redis informations."""
|
|
@@ -889,16 +920,18 @@ class RedisCache(MutableMapping):
|
|
|
889
920
|
class PrefixedRedisCache(RedisCache):
|
|
890
921
|
"""Prefixed Redis wrapper class for cachetools.
|
|
891
922
|
|
|
892
|
-
:
|
|
893
|
-
:param prefix: post key encoding prefix, default is empty.
|
|
894
|
-
:param ttl: time-to-live in seconds, used as default expiration (``ex``), default is 600.
|
|
923
|
+
Parameters:
|
|
895
924
|
|
|
896
|
-
|
|
925
|
+
- cache: actual redis cache.
|
|
926
|
+
- prefix: post key encoding prefix, default is empty.
|
|
927
|
+
- ttl: time-to-live in seconds, used as default expiration (`ex`), default is _600_.
|
|
897
928
|
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
929
|
+
```python
|
|
930
|
+
import redis
|
|
931
|
+
import CacheToolsUtils as ctu
|
|
932
|
+
# redis with "app." prefix and 1 hour expiration
|
|
933
|
+
cache = ctu.PrefixedRedisCache(redis.Redis(host="localhost"), "app.", 3600)
|
|
934
|
+
```
|
|
902
935
|
"""
|
|
903
936
|
|
|
904
937
|
def __init__(self, cache, prefix: str = "", ttl=600):
|
|
@@ -919,5 +952,3 @@ class StatsRedisCache(PrefixedRedisCache):
|
|
|
919
952
|
|
|
920
953
|
def flushdb(self):
|
|
921
954
|
self._cache.clear()
|
|
922
|
-
|
|
923
|
-
pass
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: CacheToolsUtils
|
|
3
|
-
Version:
|
|
3
|
+
Version: 12.0
|
|
4
4
|
Summary: Cachetools Utilities
|
|
5
5
|
Author-email: Fabien Coelho <cachetools.utils@coelho.net>
|
|
6
|
-
License: CC0
|
|
6
|
+
License-Expression: CC0-1.0
|
|
7
7
|
Project-URL: repository, https://github.com/zx80/cachetools-utils
|
|
8
8
|
Project-URL: documentation, https://zx80.github.io/cachetools-utils/
|
|
9
9
|
Project-URL: issues, https://github.com/zx80/cachetools-utils/issues
|
|
10
10
|
Project-URL: package, https://pypi.org/project/CacheToolsUtils/
|
|
11
11
|
Classifier: Development Status :: 5 - Production/Stable
|
|
12
12
|
Classifier: Intended Audience :: Developers
|
|
13
|
-
Classifier: License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
|
|
14
13
|
Classifier: Programming Language :: Python
|
|
15
14
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
16
15
|
Requires-Python: >=3.10
|
|
@@ -27,11 +26,9 @@ Requires-Dist: pytest; extra == "dev"
|
|
|
27
26
|
Requires-Dist: coverage; extra == "dev"
|
|
28
27
|
Requires-Dist: pymarkdownlnt; extra == "dev"
|
|
29
28
|
Provides-Extra: doc
|
|
30
|
-
Requires-Dist:
|
|
31
|
-
Requires-Dist:
|
|
32
|
-
Requires-Dist:
|
|
33
|
-
Requires-Dist: sphinx-lint; extra == "doc"
|
|
34
|
-
Requires-Dist: myst_parser; extra == "doc"
|
|
29
|
+
Requires-Dist: mkdocs; extra == "doc"
|
|
30
|
+
Requires-Dist: mkdocs-material; extra == "doc"
|
|
31
|
+
Requires-Dist: mkdocstrings[python]; extra == "doc"
|
|
35
32
|
Provides-Extra: crypt
|
|
36
33
|
Requires-Dist: pycryptodome; extra == "crypt"
|
|
37
34
|
Provides-Extra: tests
|
|
@@ -41,6 +38,7 @@ Provides-Extra: pub
|
|
|
41
38
|
Requires-Dist: build; extra == "pub"
|
|
42
39
|
Requires-Dist: wheel; extra == "pub"
|
|
43
40
|
Requires-Dist: twine; extra == "pub"
|
|
41
|
+
Dynamic: license-file
|
|
44
42
|
|
|
45
43
|
# CacheToolsUtils
|
|
46
44
|
|
|
@@ -4,17 +4,16 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "CacheToolsUtils"
|
|
7
|
-
version = "
|
|
7
|
+
version = "12.0"
|
|
8
8
|
authors = [ { name = "Fabien Coelho", email = "cachetools.utils@coelho.net" } ]
|
|
9
9
|
description = "Cachetools Utilities"
|
|
10
10
|
readme = "README.md"
|
|
11
|
-
license =
|
|
11
|
+
license = "CC0-1.0"
|
|
12
12
|
requires-python = ">= 3.10"
|
|
13
13
|
dependencies = [ "cachetools" ]
|
|
14
14
|
classifiers = [
|
|
15
15
|
"Development Status :: 5 - Production/Stable",
|
|
16
16
|
"Intended Audience :: Developers",
|
|
17
|
-
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
|
|
18
17
|
"Programming Language :: Python",
|
|
19
18
|
"Topic :: Software Development :: Libraries :: Python Modules"
|
|
20
19
|
]
|
|
@@ -37,7 +36,11 @@ dev = [
|
|
|
37
36
|
"pytest", "coverage",
|
|
38
37
|
"pymarkdownlnt",
|
|
39
38
|
]
|
|
40
|
-
doc = [ "
|
|
39
|
+
doc = [ "mkdocs", "mkdocs-material", "mkdocstrings[python]" ]
|
|
41
40
|
crypt = [ "pycryptodome" ]
|
|
42
41
|
tests = [ "pymemcache", "redis" ]
|
|
43
42
|
pub = [ "build", "wheel", "twine" ]
|
|
43
|
+
|
|
44
|
+
[tool.ruff.lint]
|
|
45
|
+
# ruff rules are what they are, but they are not always right
|
|
46
|
+
ignore = ["BLE001", "B006", "I001", "RUF012"]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|