CacheToolsUtils 10.4__py3-none-any.whl → 11.0__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.
CacheToolsUtils.py CHANGED
@@ -28,7 +28,7 @@ _NO_DEFAULT = object()
28
28
 
29
29
 
30
30
  class _MutMapMix:
31
- """Convenient MutableMapping Mixin, forward to _cache."""
31
+ """Convenient MutableMapping Mixin, forward to `_cache`."""
32
32
 
33
33
  # FIXME coverage reports this as missing with Python 3.14
34
34
  _cache: MutableMapping # pragma: no cover
@@ -53,7 +53,7 @@ class _MutMapMix:
53
53
 
54
54
 
55
55
  class _KeyMutMapMix(_MutMapMix):
56
- """Convenient MutableMapping Mixin with a key filter, forward to _cache."""
56
+ """Convenient MutableMapping Mixin with a key filter, forward to `_cache`."""
57
57
 
58
58
  @abc.abstractmethod
59
59
  def _key(self, key: Any) -> Any: # pragma: no cover
@@ -73,7 +73,7 @@ class _KeyMutMapMix(_MutMapMix):
73
73
 
74
74
 
75
75
  class _StatsMix:
76
- """Convenient Mixin to forward stats methods to _cache."""
76
+ """Convenient Mixin to forward stats methods to `_cache`."""
77
77
 
78
78
  def hits(self) -> float|None:
79
79
  return self._cache.hits() # type: ignore
@@ -114,9 +114,11 @@ class _RedisMix: # pragma: no cover
114
114
  class DebugCache(_StatsMix, MutableMapping):
115
115
  """Debug class.
116
116
 
117
- :param cache: actual cache
118
- :param log: logging instance
119
- :param name: name of instance for output
117
+ Parameters:
118
+
119
+ - cache: actual cache
120
+ - log: logging instance
121
+ - name: name of instance for output
120
122
  """
121
123
 
122
124
  def __init__(self, cache: MutableMapping, log: logging.Logger, name="cache"):
@@ -162,7 +164,7 @@ class DebugCache(_StatsMix, MutableMapping):
162
164
 
163
165
 
164
166
  class DictCache(_MutMapMix, MutableMapping):
165
- """Cache class based on dict."""
167
+ """Cache class based on `dict`."""
166
168
 
167
169
  def __init__(self):
168
170
  self._cache = dict()
@@ -174,17 +176,19 @@ class DictCache(_MutMapMix, MutableMapping):
174
176
  class LockedCache(_MutMapMix, _StatsMix, _RedisMix, MutableMapping):
175
177
  """Cache class with a lock.
176
178
 
177
- :param cache: actual cache.
178
- :param lock: lock (context manager) to use
179
+ Parameters:
179
180
 
180
- The locked layer should be the last one before the actual cache.
181
+ - cache: actual cache.
182
+ - lock: lock (context manager) to use
181
183
 
182
- .. code-block: python
184
+ The locked layer should be the last one before the actual cache.
183
185
 
184
- import threading
185
- import cachetools as ct
186
- import CacheToolsUtils as ctu
187
- cache = ctu.LockedCache(ct.LFUCache(), threading.RLock())
186
+ ```python
187
+ import threading
188
+ import cachetools as ct
189
+ import CacheToolsUtils as ctu
190
+ cache = ctu.LockedCache(ct.LFUCache(), threading.RLock())
191
+ ```
188
192
  """
189
193
 
190
194
  def __init__(self, cache: MutableMapping, lock):
@@ -211,8 +215,10 @@ class LockedCache(_MutMapMix, _StatsMix, _RedisMix, MutableMapping):
211
215
  class PrefixedCache(_KeyMutMapMix, _StatsMix, MutableMapping):
212
216
  """Cache class to add a key prefix.
213
217
 
214
- :param cache: actual cache.
215
- :param prefix: prefix to prepend to keys.
218
+ Parameters:
219
+
220
+ - cache: actual cache.
221
+ - prefix: prefix to prepend to keys.
216
222
  """
217
223
 
218
224
  def __init__(self, cache: MutableMapping, prefix: str|bytes = ""):
@@ -232,9 +238,11 @@ class PrefixedCache(_KeyMutMapMix, _StatsMix, MutableMapping):
232
238
  class AutoPrefixedCache(PrefixedCache):
233
239
  """Cache class with an automatic counter-based string prefix.
234
240
 
235
- :param cache: actual cache.
236
- :param sep: prefix separator, default is ".".
237
- :param method: encoding method in "b64", "b64u", "b32", "b32x", "b16",
241
+ Parameters:
242
+
243
+ - cache: actual cache.
244
+ - sep: prefix separator, default is ".".
245
+ - method: encoding method in "b64", "b64u", "b32", "b32x", "b16",
238
246
  "a85" and "b85". Default is "b64".
239
247
  """
240
248
 
@@ -265,16 +273,17 @@ class AutoPrefixedCache(PrefixedCache):
265
273
  class StatsCache(_MutMapMix, MutableMapping):
266
274
  """Cache class to keep stats.
267
275
 
268
- :param cache: actual cache.
276
+ Parameter:
269
277
 
270
- .. code-block: python
278
+ - cache: actual cache.
271
279
 
272
- import cachetools as ct
273
- import CacheToolsUtils as ctu
274
- cache = ctu.StatsCache(ct.LRUCache())
275
- ...
280
+ ```python
281
+ import cachetools as ct
282
+ import CacheToolsUtils as ctu
283
+ cache = ctu.StatsCache(ct.LRUCache())
284
+ ```
276
285
 
277
- Note that CacheTools ``cached`` decorator with ``info=True`` provides
286
+ Note that CacheTools `cached` decorator with `info=True` provides
278
287
  hits, misses, maxsize and currsize information.
279
288
  However, this only works for its own classes.
280
289
  """
@@ -329,9 +338,11 @@ class StatsCache(_MutMapMix, MutableMapping):
329
338
  class TwoLevelCache(_MutMapMix, MutableMapping):
330
339
  """Two-Level Cache class for CacheTools.
331
340
 
332
- :param cache: first (smaller, shorter TTL) cache
333
- :param cache2: second (larger, longer TTL) cache
334
- :param resilient: whether to ignore cache2 failures
341
+ Parameters:
342
+
343
+ - cache: first (smaller, shorter TTL) cache
344
+ - cache2: second (larger, longer TTL) cache
345
+ - resilient: whether to ignore cache2 failures
335
346
  """
336
347
 
337
348
  def __init__(self, cache: MutableMapping, cache2: MutableMapping, resilient=False):
@@ -457,10 +468,12 @@ class _Cipher:
457
468
  class EncryptedCache(_KeyMutMapMix, _StatsMix, MutableMapping):
458
469
  """Encrypted Bytes Key-Value Cache.
459
470
 
460
- :param secret: bytes of secret, at least 16 bytes.
461
- :param hsize: size of hashed key, default is *16*.
462
- :param csize: value checksum size, default is *0*.
463
- :param cipher: chose cipher from "Salsa20", "AES-128-CBC" or "ChaCha20".
471
+ Parameters:
472
+
473
+ - secret: bytes of secret, at least 16 bytes.
474
+ - hsize: size of hashed key, default is *16*.
475
+ - csize: value checksum size, default is *0*.
476
+ - cipher: chose cipher from "Salsa20", "AES-128-CBC" or "ChaCha20".
464
477
 
465
478
  The key is *not* encrypted but simply hashed, thus they are
466
479
  fixed size with a very low collision probability.
@@ -553,14 +566,16 @@ class ToBytesCache(_KeyMutMapMix, _StatsMix, MutableMapping):
553
566
  def cached(cache, *args, **kwargs):
554
567
  """Extended decorator with delete and exists.
555
568
 
556
- All parameters are forwarded to ``cachetools.cached``.
569
+ All parameters are forwarded to `cachetools.cached`.
570
+
571
+ Parameter:
557
572
 
558
- :param cache: actual cache.
573
+ - cache: actual cache.
559
574
 
560
- If *f(\\*args, \\*\\*kwargs)* is the ``cached`` function, then:
575
+ If *f(\\*args, \\*\\*kwargs)* is the _cached_ function, then:
561
576
 
562
- - ``f.cache_in(*args, **kwargs)`` tells whether the result is cached.
563
- - ``f.cache_del(*args, **kwargs)`` deletes (invalidates) the cached result.
577
+ - `f.cache_in(*args, **kwargs)` tells whether the result is cached.
578
+ - `f.cache_del(*args, **kwargs)` deletes (invalidates) the cached result.
564
579
  """
565
580
 
566
581
  def decorate(fun: Callable):
@@ -603,15 +618,17 @@ def cacheMethods(
603
618
  ):
604
619
  """Cache some object methods.
605
620
 
606
- :param cache: cache to use.
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
621
+ Parameters:
611
622
 
612
- .. code-block:: python
623
+ - cache: cache to use.
624
+ - obj: object instance to be cached.
625
+ - gen: generator of PrefixedCache.
626
+ - opts: additional parameters when calling `cached`.
627
+ - funs: name of methods and corresponding prefix
613
628
 
614
- cacheMethods(cache, item, PrefixedCache, compute1="c1.", compute2="c2.")
629
+ ```python
630
+ cacheMethods(cache, item, PrefixedCache, compute1="c1.", compute2="c2.")
631
+ ```
615
632
  """
616
633
  for fun, prefix in funs.items():
617
634
  assert hasattr(obj, fun), f"cannot cache missing method {fun} on {obj}"
@@ -630,15 +647,17 @@ def cacheFunctions(
630
647
  ):
631
648
  """Cache some global functions, with a prefix.
632
649
 
633
- :param cache: cache to use.
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
650
+ Parameters:
638
651
 
639
- .. code-block:: python
652
+ - cache: cache to use.
653
+ - globs: global object dictionary.
654
+ - gen: generator of PrefixedCache.
655
+ - opts: additional parameters when calling `cached`.
656
+ - funs: name of functions and corresponding prefix
640
657
 
641
- cacheFunctions(cache, globals(), PrefixedCache, fun1="f1.", fun2="f2.")
658
+ ```python
659
+ cacheFunctions(cache, globals(), PrefixedCache, fun1="f1.", fun2="f2.")
660
+ ```
642
661
  """
643
662
  for fun, prefix in funs.items():
644
663
  assert fun in globs, "caching functions: {fun} not found"
@@ -697,13 +716,13 @@ def full_hash_key(*args, **kwargs) -> str:
697
716
  # MEMCACHED
698
717
  #
699
718
  class JsonSerde:
700
- """JSON serialize/deserialize class for MemCached (``pymemcache``).
701
-
702
- .. code-block:: python
719
+ """JSON serialize/deserialize class for MemCached (`pymemcache`).
703
720
 
704
- import pymemcache as pmc
705
- import CacheToolsUtils as ctu
706
- pmc_cache = pmc.Client(server="localhost", serde=ctu.JsonSerde())
721
+ ```python
722
+ import pymemcache as pmc
723
+ import CacheToolsUtils as ctu
724
+ pmc_cache = pmc.Client(server="localhost", serde=ctu.JsonSerde())
725
+ ```
707
726
  """
708
727
 
709
728
  # keep strings, else json
@@ -730,16 +749,19 @@ class JsonSerde:
730
749
  class MemCached(_KeyMutMapMix, MutableMapping):
731
750
  """MemCached-compatible wrapper class for cachetools with key encoding.
732
751
 
733
- :param cache: actual memcached cache.
752
+ Parameter:
734
753
 
735
- .. code-block:: python
754
+ - cache: actual memcached cache.
736
755
 
737
- import pymemcache as pmc
738
- import CacheToolsUtils as ctu
739
- cache = ctu.MemCached(pmc.Client(server="localhost", serde=ctu.JsonSerde()))
756
+ ```python
757
+ import pymemcache as pmc
758
+ import CacheToolsUtils as ctu
759
+ cache = ctu.MemCached(pmc.Client(server="localhost", serde=ctu.JsonSerde()))
740
760
 
741
- @ctu.cached(cache=cache)
742
- def whatever(...):
761
+ @ctu.cached(cache=cache)
762
+ def whatever(...):
763
+ ...
764
+ ```
743
765
  """
744
766
 
745
767
  def __init__(self, cache):
@@ -773,15 +795,17 @@ class MemCached(_KeyMutMapMix, MutableMapping):
773
795
  class PrefixedMemCached(MemCached):
774
796
  """MemCached-compatible wrapper class for cachetools with a key prefix.
775
797
 
776
- :param cache: actual memcached cache.
777
- :param prefix: post key-encoding prepended prefix.
798
+ Parameters:
778
799
 
779
- .. code-block:: python
800
+ - cache: actual memcached cache.
801
+ - prefix: post key-encoding prepended prefix.
780
802
 
781
- import pymemcache as pmc
782
- import CacheToolsUtils as ctu
783
- # add a "app." prefix to keys, after serialization
784
- cache = ctu.PrefixedMemCached(pmc.Client(server="localhost", serde=ctu.JsonSerde()), "app.")
803
+ ```python
804
+ import pymemcache as pmc
805
+ import CacheToolsUtils as ctu
806
+ # add a "app." prefix to keys, after serialization
807
+ cache = ctu.PrefixedMemCached(pmc.Client(server="localhost", serde=ctu.JsonSerde()), "app.")
808
+ ```
785
809
  """
786
810
 
787
811
  def __init__(self, cache, prefix: str = ""):
@@ -796,20 +820,22 @@ class PrefixedMemCached(MemCached):
796
820
  # REDIS
797
821
  #
798
822
  class RedisCache(MutableMapping):
799
- """Redis TTL-ed wrapper for cachetools (``redis``).
823
+ """Redis TTL-ed wrapper for cachetools (`redis`).
800
824
 
801
- :param cache: actual redis cache.
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*.
825
+ Parameters:
804
826
 
805
- Keys and values are serialized in *JSON*.
827
+ - cache: actual redis cache.
828
+ - ttl: time-to-live in seconds, used as default expiration (`ex`), default is _600_.
829
+ - raw: whether to serialize keys and values, default is *False*.
806
830
 
807
- .. code-block:: python
831
+ Keys and values are serialized in *JSON*.
808
832
 
809
- import redis
810
- import CacheToolsUtils as ctu
811
- # redis with 1 hour expiration
812
- cache = ctu.RedisCache(redis.Redis(host="localhost"), 3600)
833
+ ```python
834
+ import redis
835
+ import CacheToolsUtils as ctu
836
+ # redis with 1 hour expiration
837
+ cache = ctu.RedisCache(redis.Redis(host="localhost"), 3600)
838
+ ```
813
839
  """
814
840
 
815
841
  def __init__(self, cache, ttl=600, raw=False):
@@ -889,16 +915,18 @@ class RedisCache(MutableMapping):
889
915
  class PrefixedRedisCache(RedisCache):
890
916
  """Prefixed Redis wrapper class for cachetools.
891
917
 
892
- :param cache: actual redis cache.
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.
918
+ Parameters:
895
919
 
896
- .. code-block:: python
920
+ - cache: actual redis cache.
921
+ - prefix: post key encoding prefix, default is empty.
922
+ - ttl: time-to-live in seconds, used as default expiration (`ex`), default is _600_.
897
923
 
898
- import redis
899
- import CacheToolsUtils as ctu
900
- # redis with "app." prefix and 1 hour expiration
901
- cache = ctu.PrefixedRedisCache(redis.Redis(host="localhost"), "app.", 3600)
924
+ ```python
925
+ import redis
926
+ import CacheToolsUtils as ctu
927
+ # redis with "app." prefix and 1 hour expiration
928
+ cache = ctu.PrefixedRedisCache(redis.Redis(host="localhost"), "app.", 3600)
929
+ ```
902
930
  """
903
931
 
904
932
  def __init__(self, cache, prefix: str = "", ttl=600):
@@ -1,16 +1,15 @@
1
- Metadata-Version: 2.2
1
+ Metadata-Version: 2.4
2
2
  Name: CacheToolsUtils
3
- Version: 10.4
3
+ Version: 11.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: sphinx; extra == "doc"
31
- Requires-Dist: sphinx_rtd_theme; extra == "doc"
32
- Requires-Dist: sphinx-autoapi; extra == "doc"
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
 
@@ -0,0 +1,6 @@
1
+ CacheToolsUtils.py,sha256=Wou-1Dj2doWJo-KFInQHnVXRL4IeOH2_78H8ArPJOP4,27556
2
+ cachetoolsutils-11.0.dist-info/licenses/LICENSE,sha256=y_yFW1bmBAUFCF-ZDyDiq10Ykns_19If5pFnZUzYgeU,33
3
+ cachetoolsutils-11.0.dist-info/METADATA,sha256=Z9bey31ynGMZwlrpcXtrfl54rd5AGlTpcIQOCvJrZaw,5407
4
+ cachetoolsutils-11.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
5
+ cachetoolsutils-11.0.dist-info/top_level.txt,sha256=qCyE4jGot5mOmvIQrZueCnPtbYtRe2hqke4sGojm3zI,16
6
+ cachetoolsutils-11.0.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.2)
2
+ Generator: setuptools (80.9.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,6 +0,0 @@
1
- CacheToolsUtils.py,sha256=uOSsktLdbzvWfBNTmMPNcPQxOHgoQclmxIYtMCFptH8,27657
2
- cachetoolsutils-10.4.dist-info/LICENSE,sha256=y_yFW1bmBAUFCF-ZDyDiq10Ykns_19If5pFnZUzYgeU,33
3
- cachetoolsutils-10.4.dist-info/METADATA,sha256=YKZ44SQN-vim2aYm4GrKhYuchKNtIxm9hCPgYzMJ2XU,5527
4
- cachetoolsutils-10.4.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
5
- cachetoolsutils-10.4.dist-info/top_level.txt,sha256=qCyE4jGot5mOmvIQrZueCnPtbYtRe2hqke4sGojm3zI,16
6
- cachetoolsutils-10.4.dist-info/RECORD,,