CacheToolsUtils 9.0__tar.gz → 9.1__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.1
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,38 @@ 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:
458
+ return json.dumps({"*": args, "**": kwargs}, sort_keys=True)
459
+ else: # array
460
+ return json.dumps(args)
461
+
462
+
463
+ # Hmmm…
464
+ class _HashJsonKey:
465
+ """A cache key with a persistant hash value."""
466
+
467
+ def __init__(self, *args, **kwargs):
468
+ self._hashed = None
469
+ self._args = args
470
+ self._kwargs = kwargs
471
+ self._key = json_key(*args, **kwargs)
472
+
473
+ def __hash__(self):
474
+ if self._hashed is None:
475
+ self._hashed = self._key.__hash__()
476
+ return self._hashed
477
+
478
+ def __str__(self):
479
+ return self._key
480
+
481
+
482
+ def hash_json_key(*args, **kwargs):
483
+ return _HashJsonKey(*args, **kwargs)
484
+
485
+
454
486
  #
455
487
  # MEMCACHED
456
488
  #
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: CacheToolsUtils
3
- Version: 9.0
3
+ Version: 9.1
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.1"
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