CacheToolsUtils 9.0__py3-none-any.whl → 9.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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CacheToolsUtils
3
- Version: 9.0
3
+ Version: 9.2
4
4
  Summary: Cachetools Utilities
5
5
  Author-email: Fabien Coelho <cachetools.utils@coelho.net>
6
6
  License: CC0
@@ -18,29 +18,29 @@ Description-Content-Type: text/markdown
18
18
  License-File: LICENSE
19
19
  Requires-Dist: cachetools
20
20
  Provides-Extra: dev
21
- Requires-Dist: mypy ; extra == 'dev'
22
- Requires-Dist: pyright ; extra == 'dev'
23
- Requires-Dist: black ; extra == 'dev'
24
- Requires-Dist: flake8 ; extra == 'dev'
25
- Requires-Dist: ruff ; extra == 'dev'
26
- Requires-Dist: pytest ; extra == 'dev'
27
- Requires-Dist: coverage ; extra == 'dev'
28
- Requires-Dist: pymarkdownlnt ; extra == 'dev'
29
- Requires-Dist: types-redis ; extra == 'dev'
30
- Requires-Dist: types-cachetools ; extra == 'dev'
21
+ Requires-Dist: mypy; extra == "dev"
22
+ Requires-Dist: pyright; extra == "dev"
23
+ Requires-Dist: black; extra == "dev"
24
+ Requires-Dist: flake8; extra == "dev"
25
+ Requires-Dist: ruff; extra == "dev"
26
+ Requires-Dist: pytest; extra == "dev"
27
+ Requires-Dist: coverage; extra == "dev"
28
+ Requires-Dist: pymarkdownlnt; extra == "dev"
29
+ Requires-Dist: types-redis; extra == "dev"
30
+ Requires-Dist: types-cachetools; extra == "dev"
31
31
  Provides-Extra: doc
32
- Requires-Dist: sphinx ; extra == 'doc'
33
- Requires-Dist: sphinx-rtd-theme ; extra == 'doc'
34
- Requires-Dist: sphinx-autoapi ; extra == 'doc'
35
- Requires-Dist: sphinx-lint ; extra == 'doc'
36
- Requires-Dist: myst-parser ; extra == 'doc'
37
- Provides-Extra: pub
38
- Requires-Dist: build ; extra == 'pub'
39
- Requires-Dist: wheel ; extra == 'pub'
40
- Requires-Dist: twine ; extra == 'pub'
32
+ Requires-Dist: sphinx; extra == "doc"
33
+ Requires-Dist: sphinx_rtd_theme; extra == "doc"
34
+ Requires-Dist: sphinx-autoapi; extra == "doc"
35
+ Requires-Dist: sphinx-lint; extra == "doc"
36
+ Requires-Dist: myst_parser; extra == "doc"
41
37
  Provides-Extra: tests
42
- Requires-Dist: pymemcache ; extra == 'tests'
43
- Requires-Dist: redis ; extra == 'tests'
38
+ Requires-Dist: pymemcache; extra == "tests"
39
+ Requires-Dist: redis; extra == "tests"
40
+ Provides-Extra: pub
41
+ Requires-Dist: build; extra == "pub"
42
+ Requires-Dist: wheel; extra == "pub"
43
+ Requires-Dist: twine; extra == "pub"
44
44
 
45
45
  # CacheToolsUtils
46
46
 
@@ -51,7 +51,7 @@ Classes to add key prefix and stats to
51
51
  and other cache-related utils.
52
52
 
53
53
  ![Status](https://github.com/zx80/cachetools-utils/actions/workflows/cachetools-utils.yml/badge.svg?branch=main&style=flat)
54
- ![Tests](https://img.shields.io/badge/tests-19%20✓-success)
54
+ ![Tests](https://img.shields.io/badge/tests-21%20✓-success)
55
55
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
56
56
  ![Issues](https://img.shields.io/github/issues/zx80/cachetools-utils?style=flat)
57
57
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -91,6 +91,7 @@ with `cachetools`.
91
91
  - `cached` decorator: a cachetools replacement which allows to test if a
92
92
  function result is in cache, and to delete such an entry.
93
93
  - `cacheFunctions` and `cacheMethods`: add caching to functions or methods.
94
+ - `json_key` and `hash_json_key`: JSON-based cache key serialization functions
94
95
 
95
96
  ## License
96
97
 
@@ -0,0 +1,6 @@
1
+ CacheToolsUtils.py,sha256=2IzulFpw9WH-7-aJs7cztR-NPdLH3TVMxN2eFyZXRc0,20350
2
+ CacheToolsUtils-9.2.dist-info/LICENSE,sha256=y_yFW1bmBAUFCF-ZDyDiq10Ykns_19If5pFnZUzYgeU,33
3
+ CacheToolsUtils-9.2.dist-info/METADATA,sha256=jWWKCdp-ShOLRzX4DvYVziFAVdh-JDPA_nvGxK7ZKnE,4483
4
+ CacheToolsUtils-9.2.dist-info/WHEEL,sha256=PZUExdf71Ui_so67QXpySuHtCi3-J3wvF4ORK6k_S8U,91
5
+ CacheToolsUtils-9.2.dist-info/top_level.txt,sha256=qCyE4jGot5mOmvIQrZueCnPtbYtRe2hqke4sGojm3zI,16
6
+ CacheToolsUtils-9.2.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.2.0)
2
+ Generator: setuptools (75.6.0)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
CacheToolsUtils.py CHANGED
@@ -451,6 +451,42 @@ def cacheFunctions(
451
451
  globs[fun] = cached(cache=gen(cache, prefix))(f)
452
452
 
453
453
 
454
+ # JSON-based key function
455
+ # NOTE obviously this only works if parameters are json-serializable…
456
+ def json_key(*args, **kwargs):
457
+ if kwargs: # object
458
+ if args:
459
+ val = {"*": args, "**": kwargs}
460
+ else:
461
+ val = {"**": kwargs}
462
+ else: # array
463
+ val = args
464
+ return json.dumps(val, sort_keys=True, separators=(",", ":"))
465
+
466
+
467
+ # Hmmm…
468
+ class _HashJsonKey:
469
+ """A cache key with a persistant hash value."""
470
+
471
+ def __init__(self, *args, **kwargs):
472
+ self._hashed = None
473
+ self._args = args
474
+ self._kwargs = kwargs
475
+ self._key = json_key(*args, **kwargs)
476
+
477
+ def __hash__(self):
478
+ if self._hashed is None:
479
+ self._hashed = self._key.__hash__()
480
+ return self._hashed
481
+
482
+ def __str__(self):
483
+ return self._key
484
+
485
+
486
+ def hash_json_key(*args, **kwargs):
487
+ return _HashJsonKey(*args, **kwargs)
488
+
489
+
454
490
  #
455
491
  # MEMCACHED
456
492
  #
@@ -1,6 +0,0 @@
1
- CacheToolsUtils.py,sha256=HSfiQx6NkUa0yWgyyj4j3eAMEA-QyLznrztd4QAKBtQ,19464
2
- CacheToolsUtils-9.0.dist-info/LICENSE,sha256=y_yFW1bmBAUFCF-ZDyDiq10Ykns_19If5pFnZUzYgeU,33
3
- CacheToolsUtils-9.0.dist-info/METADATA,sha256=MHZGUt_7_7ATiQn0ZetFecucS5Mjjs-dmqlJj3prots,4424
4
- CacheToolsUtils-9.0.dist-info/WHEEL,sha256=OVMc5UfuAQiSplgO0_WdW7vXVGAt9Hdd6qtN4HotdyA,91
5
- CacheToolsUtils-9.0.dist-info/top_level.txt,sha256=qCyE4jGot5mOmvIQrZueCnPtbYtRe2hqke4sGojm3zI,16
6
- CacheToolsUtils-9.0.dist-info/RECORD,,