CacheToolsUtils 9.0__tar.gz → 9.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.
@@ -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
@@ -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
 
@@ -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 +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
@@ -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
 
@@ -7,7 +7,7 @@ Classes to add key prefix and stats to
7
7
  and other cache-related utils.
8
8
 
9
9
  ![Status](https://github.com/zx80/cachetools-utils/actions/workflows/cachetools-utils.yml/badge.svg?branch=main&style=flat)
10
- ![Tests](https://img.shields.io/badge/tests-19%20✓-success)
10
+ ![Tests](https://img.shields.io/badge/tests-21%20✓-success)
11
11
  ![Coverage](https://img.shields.io/badge/coverage-100%25-success)
12
12
  ![Issues](https://img.shields.io/github/issues/zx80/cachetools-utils?style=flat)
13
13
  ![Python](https://img.shields.io/badge/python-3-informational)
@@ -47,6 +47,7 @@ with `cachetools`.
47
47
  - `cached` decorator: a cachetools replacement which allows to test if a
48
48
  function result is in cache, and to delete such an entry.
49
49
  - `cacheFunctions` and `cacheMethods`: add caching to functions or methods.
50
+ - `json_key` and `hash_json_key`: JSON-based cache key serialization functions
50
51
 
51
52
  ## License
52
53
 
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "CacheToolsUtils"
7
- version = "9.0"
7
+ version = "9.2"
8
8
  authors = [ { name = "Fabien Coelho", email = "cachetools.utils@coelho.net" } ]
9
9
  description = "Cachetools Utilities"
10
10
  readme = "README.md"
File without changes
File without changes
File without changes