CacheToolsUtils 10.2__tar.gz → 10.3__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.2 → cachetoolsutils-10.3}/CacheToolsUtils.egg-info/PKG-INFO +4 -3
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/CacheToolsUtils.py +33 -0
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/PKG-INFO +4 -3
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/README.md +2 -1
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/pyproject.toml +1 -1
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/CacheToolsUtils.egg-info/SOURCES.txt +0 -0
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/CacheToolsUtils.egg-info/dependency_links.txt +0 -0
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/CacheToolsUtils.egg-info/requires.txt +0 -0
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/CacheToolsUtils.egg-info/top_level.txt +0 -0
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/LICENSE +0 -0
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/MANIFEST.in +0 -0
- {cachetoolsutils-10.2 → cachetoolsutils-10.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: CacheToolsUtils
|
|
3
|
-
Version: 10.
|
|
3
|
+
Version: 10.3
|
|
4
4
|
Summary: Cachetools Utilities
|
|
5
5
|
Author-email: Fabien Coelho <cachetools.utils@coelho.net>
|
|
6
6
|
License: CC0
|
|
@@ -53,7 +53,7 @@ Classes to add key prefix and stats to
|
|
|
53
53
|
and other cache-related utils.
|
|
54
54
|
|
|
55
55
|

|
|
56
|
-

|
|
57
57
|

|
|
58
58
|

|
|
59
59
|

|
|
@@ -81,6 +81,7 @@ with `cachetools`.
|
|
|
81
81
|
|
|
82
82
|
- `PrefixedCache`, `PrefixedMemCached` and `PrefixedRedisCache` add a prefix to
|
|
83
83
|
distinguish sources on a shared cache.
|
|
84
|
+
- `AutoPrefixedCache` add a counter-based prefix.
|
|
84
85
|
- `StatsCache`, `MemCached` and `RedisCache` add a `hits` method
|
|
85
86
|
to report the cache hit rate, `stats` to report statistics and
|
|
86
87
|
`reset` to reset statistics.
|
|
@@ -226,6 +226,39 @@ class PrefixedCache(_KeyMutMapMix, _StatsMix, MutableMapping):
|
|
|
226
226
|
return self._prefix + self._cast(key) # type: ignore
|
|
227
227
|
|
|
228
228
|
|
|
229
|
+
class AutoPrefixedCache(PrefixedCache):
|
|
230
|
+
"""Cache class with an automatic counter-based string prefix.
|
|
231
|
+
|
|
232
|
+
:param cache: actual cache.
|
|
233
|
+
:param sep: prefix separator, default is ".".
|
|
234
|
+
:param method: encoding method in "b64", "b64u", "b32", "b32x", "b16",
|
|
235
|
+
"a85" and "b85". Default is "b64".
|
|
236
|
+
"""
|
|
237
|
+
|
|
238
|
+
_COUNTER: int = 0
|
|
239
|
+
|
|
240
|
+
_METHODS: dict[str, Callable[[Any], bytes]] = {
|
|
241
|
+
"b64": base64.b64encode,
|
|
242
|
+
"b64u": base64.urlsafe_b64encode,
|
|
243
|
+
"b32": base64.b32encode,
|
|
244
|
+
"b32x": base64.b32hexencode,
|
|
245
|
+
"b16": base64.b16encode,
|
|
246
|
+
"a85": base64.a85encode,
|
|
247
|
+
"b85": base64.b85encode,
|
|
248
|
+
# "z85": base64.z85encode, # Python 3.13
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
def __init__(self, cache: MutableMapping, sep: str = ".", method: str = "b64"):
|
|
252
|
+
if method not in AutoPrefixedCache._METHODS:
|
|
253
|
+
raise Exception(f"invalid conversion method: {method}")
|
|
254
|
+
encoder = AutoPrefixedCache._METHODS[method]
|
|
255
|
+
length = max(1, (AutoPrefixedCache._COUNTER.bit_length() + 7) // 8)
|
|
256
|
+
# NOTE byteorder default added to 3.11
|
|
257
|
+
prefix = encoder(AutoPrefixedCache._COUNTER.to_bytes(length, byteorder="big")).decode("ASCII")
|
|
258
|
+
AutoPrefixedCache._COUNTER += 1
|
|
259
|
+
super().__init__(cache, prefix + sep)
|
|
260
|
+
|
|
261
|
+
|
|
229
262
|
class StatsCache(_MutMapMix, MutableMapping):
|
|
230
263
|
"""Cache class to keep stats.
|
|
231
264
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.2
|
|
2
2
|
Name: CacheToolsUtils
|
|
3
|
-
Version: 10.
|
|
3
|
+
Version: 10.3
|
|
4
4
|
Summary: Cachetools Utilities
|
|
5
5
|
Author-email: Fabien Coelho <cachetools.utils@coelho.net>
|
|
6
6
|
License: CC0
|
|
@@ -53,7 +53,7 @@ Classes to add key prefix and stats to
|
|
|
53
53
|
and other cache-related utils.
|
|
54
54
|
|
|
55
55
|

|
|
56
|
-

|
|
57
57
|

|
|
58
58
|

|
|
59
59
|

|
|
@@ -81,6 +81,7 @@ with `cachetools`.
|
|
|
81
81
|
|
|
82
82
|
- `PrefixedCache`, `PrefixedMemCached` and `PrefixedRedisCache` add a prefix to
|
|
83
83
|
distinguish sources on a shared cache.
|
|
84
|
+
- `AutoPrefixedCache` add a counter-based prefix.
|
|
84
85
|
- `StatsCache`, `MemCached` and `RedisCache` add a `hits` method
|
|
85
86
|
to report the cache hit rate, `stats` to report statistics and
|
|
86
87
|
`reset` to reset statistics.
|
|
@@ -7,7 +7,7 @@ Classes to add key prefix and stats to
|
|
|
7
7
|
and other cache-related utils.
|
|
8
8
|
|
|
9
9
|

|
|
10
|
-

|
|
11
11
|

|
|
12
12
|

|
|
13
13
|

|
|
@@ -35,6 +35,7 @@ with `cachetools`.
|
|
|
35
35
|
|
|
36
36
|
- `PrefixedCache`, `PrefixedMemCached` and `PrefixedRedisCache` add a prefix to
|
|
37
37
|
distinguish sources on a shared cache.
|
|
38
|
+
- `AutoPrefixedCache` add a counter-based prefix.
|
|
38
39
|
- `StatsCache`, `MemCached` and `RedisCache` add a `hits` method
|
|
39
40
|
to report the cache hit rate, `stats` to report statistics and
|
|
40
41
|
`reset` to reset statistics.
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|