CacheToolsUtils 8.5__tar.gz → 9.0__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-8.5 → cachetoolsutils-9.0}/CacheToolsUtils.egg-info/PKG-INFO +15 -9
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/CacheToolsUtils.egg-info/requires.txt +1 -0
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/CacheToolsUtils.py +46 -7
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/PKG-INFO +15 -9
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/README.md +13 -8
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/pyproject.toml +2 -2
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/CacheToolsUtils.egg-info/SOURCES.txt +0 -0
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/CacheToolsUtils.egg-info/dependency_links.txt +0 -0
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/CacheToolsUtils.egg-info/top_level.txt +0 -0
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/LICENSE +0 -0
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/MANIFEST.in +0 -0
- {CacheToolsUtils-8.5 → cachetoolsutils-9.0}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CacheToolsUtils
|
|
3
|
-
Version:
|
|
3
|
+
Version: 9.0
|
|
4
4
|
Summary: Cachetools Utilities
|
|
5
5
|
Author-email: Fabien Coelho <cachetools.utils@coelho.net>
|
|
6
6
|
License: CC0
|
|
@@ -22,6 +22,7 @@ Requires-Dist: mypy; extra == "dev"
|
|
|
22
22
|
Requires-Dist: pyright; extra == "dev"
|
|
23
23
|
Requires-Dist: black; extra == "dev"
|
|
24
24
|
Requires-Dist: flake8; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff; extra == "dev"
|
|
25
26
|
Requires-Dist: pytest; extra == "dev"
|
|
26
27
|
Requires-Dist: coverage; extra == "dev"
|
|
27
28
|
Requires-Dist: pymarkdownlnt; extra == "dev"
|
|
@@ -50,7 +51,7 @@ Classes to add key prefix and stats to
|
|
|
50
51
|
and other cache-related utils.
|
|
51
52
|
|
|
52
53
|

|
|
53
|
-

|
|
54
55
|

|
|
55
56
|

|
|
56
57
|

|
|
@@ -74,12 +75,13 @@ with `cachetools`.
|
|
|
74
75
|
class for Memcached.
|
|
75
76
|
- `DictCache` a very simple `dict` cache.
|
|
76
77
|
|
|
77
|
-
###
|
|
78
|
+
### Wrappers to extend cache capabilities
|
|
78
79
|
|
|
79
80
|
- `PrefixedCache`, `PrefixedMemCached` and `PrefixedRedisCache` add a prefix to
|
|
80
81
|
distinguish sources on a shared cache.
|
|
81
|
-
- `StatsCache`, `
|
|
82
|
-
to report the cache hit rate
|
|
82
|
+
- `StatsCache`, `MemCached` and `RedisCache` add a `hits` method
|
|
83
|
+
to report the cache hit rate, `stats` to report statistics and
|
|
84
|
+
`reset` to reset statistics.
|
|
83
85
|
- `LockedCache` use a (thread) lock to control cache accesses.
|
|
84
86
|
- `TwoLevelCache` allows to combine two caches.
|
|
85
87
|
- `DebugCache` to trace cache calls using `logging`.
|
|
@@ -90,6 +92,14 @@ with `cachetools`.
|
|
|
90
92
|
function result is in cache, and to delete such an entry.
|
|
91
93
|
- `cacheFunctions` and `cacheMethods`: add caching to functions or methods.
|
|
92
94
|
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
This code is [Public Domain](https://creativecommons.org/publicdomain/zero/1.0/).
|
|
98
|
+
|
|
99
|
+
All software has bug, this is software, hence… Beware that you may lose your
|
|
100
|
+
hairs or your friends because of it. If you like it, feel free to send a
|
|
101
|
+
postcard to the author.
|
|
102
|
+
|
|
93
103
|
## More
|
|
94
104
|
|
|
95
105
|
See the
|
|
@@ -98,7 +108,3 @@ See the
|
|
|
98
108
|
[issues](https://github.com/zx80/cachetools-utils/issues) on GitHub.
|
|
99
109
|
|
|
100
110
|
See [packages](https://pypi.org/project/CacheToolsUtils/) on PyPI.
|
|
101
|
-
|
|
102
|
-
## License
|
|
103
|
-
|
|
104
|
-
This code is public domain.
|
|
@@ -25,7 +25,8 @@ _NO_DEFAULT = object()
|
|
|
25
25
|
class _MutMapMix:
|
|
26
26
|
"""Convenient MutableMapping Mixin, forward to _cache."""
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
# FIXME coverage reports this as missing with Python 3.14
|
|
29
|
+
_cache: MutableMapping # pragma: no cover
|
|
29
30
|
|
|
30
31
|
def __contains__(self, key):
|
|
31
32
|
return self._cache.__contains__(key)
|
|
@@ -69,9 +70,12 @@ class _KeyMutMapMix(_MutMapMix):
|
|
|
69
70
|
class _StatsMix:
|
|
70
71
|
"""Convenient Mixin to forward stats methods to _cache."""
|
|
71
72
|
|
|
72
|
-
def hits(self):
|
|
73
|
+
def hits(self) -> float|None:
|
|
73
74
|
return self._cache.hits() # type: ignore
|
|
74
75
|
|
|
76
|
+
def stats(self) -> dict[str, Any]:
|
|
77
|
+
return self._cache.stats() # type: ignore
|
|
78
|
+
|
|
75
79
|
def reset(self):
|
|
76
80
|
return self._cache.reset() # type: ignore
|
|
77
81
|
|
|
@@ -102,7 +106,7 @@ class _RedisMix: # pragma: no cover
|
|
|
102
106
|
# CACHETOOLS EXTENSIONS
|
|
103
107
|
#
|
|
104
108
|
|
|
105
|
-
class DebugCache(MutableMapping):
|
|
109
|
+
class DebugCache(_StatsMix, MutableMapping):
|
|
106
110
|
"""Debug class.
|
|
107
111
|
|
|
108
112
|
:param cache: actual cache
|
|
@@ -241,14 +245,25 @@ class StatsCache(_MutMapMix, MutableMapping):
|
|
|
241
245
|
self._cache = cache
|
|
242
246
|
self.reset()
|
|
243
247
|
|
|
244
|
-
def hits(self):
|
|
248
|
+
def hits(self) -> float:
|
|
245
249
|
"""Return the cache hit ratio."""
|
|
246
|
-
return float(self._hits) /
|
|
250
|
+
return float(self._hits) / max(self._reads, 1)
|
|
247
251
|
|
|
248
252
|
def reset(self):
|
|
249
253
|
"""Reset internal stats data."""
|
|
250
254
|
self._reads, self._writes, self._dels, self._hits = 0, 0, 0, 0
|
|
251
255
|
|
|
256
|
+
def stats(self) -> dict[str, Any]:
|
|
257
|
+
"""Return available stats data as dict."""
|
|
258
|
+
return {
|
|
259
|
+
"type": 1,
|
|
260
|
+
"reads": self._reads,
|
|
261
|
+
"writes": self._writes,
|
|
262
|
+
"dels": self._dels,
|
|
263
|
+
"hits": self.hits(),
|
|
264
|
+
"size": self._cache.__len__()
|
|
265
|
+
}
|
|
266
|
+
|
|
252
267
|
def __getitem__(self, key):
|
|
253
268
|
self._reads += 1
|
|
254
269
|
res = self._cache.__getitem__(key)
|
|
@@ -324,6 +339,27 @@ class TwoLevelCache(_MutMapMix, MutableMapping):
|
|
|
324
339
|
# NOTE not passed on cache2…
|
|
325
340
|
return self._cache.clear()
|
|
326
341
|
|
|
342
|
+
def stats(self) -> dict[str, Any]:
|
|
343
|
+
data = {"type": 2}
|
|
344
|
+
try:
|
|
345
|
+
data["cache1"] = self._cache.stats() # type: ignore
|
|
346
|
+
except Exception:
|
|
347
|
+
data["cache1"] = {} # type: ignore
|
|
348
|
+
try:
|
|
349
|
+
data["cache2"] = self._cache2.stats() # type: ignore
|
|
350
|
+
except Exception:
|
|
351
|
+
data["cache2"] = {} # type: ignore
|
|
352
|
+
return data
|
|
353
|
+
|
|
354
|
+
def hits(self) -> float|None:
|
|
355
|
+
data = self.stats()
|
|
356
|
+
c1, c2 = data["cache1"], data["cache2"]
|
|
357
|
+
if (c1 and "type" in c1 and c1["type"] == 1 and
|
|
358
|
+
c2 and "type" in c2 and c2["type"] == 1):
|
|
359
|
+
return float(c1["hits"] + c2["hits"]) / max(c1["reads"] + c2["reads"], 1)
|
|
360
|
+
# else
|
|
361
|
+
return None
|
|
362
|
+
|
|
327
363
|
def reset(self): # pragma: no cover
|
|
328
364
|
self._cache.reset() # type: ignore
|
|
329
365
|
self._cache2.reset() # type: ignore
|
|
@@ -586,6 +622,9 @@ class RedisCache(MutableMapping):
|
|
|
586
622
|
"""Return redis informations."""
|
|
587
623
|
return self._cache.info(*args, **kwargs)
|
|
588
624
|
|
|
625
|
+
def stats(self) -> dict[str, Any]:
|
|
626
|
+
return self.info(section="stats")
|
|
627
|
+
|
|
589
628
|
def dbsize(self, *args, **kwargs):
|
|
590
629
|
"""Return redis database size."""
|
|
591
630
|
return self._cache.dbsize(*args, **kwargs)
|
|
@@ -606,9 +645,9 @@ class RedisCache(MutableMapping):
|
|
|
606
645
|
del self[index]
|
|
607
646
|
|
|
608
647
|
# stats
|
|
609
|
-
def hits(self):
|
|
648
|
+
def hits(self) -> float:
|
|
610
649
|
"""Return cache hits."""
|
|
611
|
-
stats = self.
|
|
650
|
+
stats = self.stats()
|
|
612
651
|
return float(stats["keyspace_hits"]) / (
|
|
613
652
|
stats["keyspace_hits"] + stats["keyspace_misses"]
|
|
614
653
|
)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: CacheToolsUtils
|
|
3
|
-
Version:
|
|
3
|
+
Version: 9.0
|
|
4
4
|
Summary: Cachetools Utilities
|
|
5
5
|
Author-email: Fabien Coelho <cachetools.utils@coelho.net>
|
|
6
6
|
License: CC0
|
|
@@ -22,6 +22,7 @@ Requires-Dist: mypy; extra == "dev"
|
|
|
22
22
|
Requires-Dist: pyright; extra == "dev"
|
|
23
23
|
Requires-Dist: black; extra == "dev"
|
|
24
24
|
Requires-Dist: flake8; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff; extra == "dev"
|
|
25
26
|
Requires-Dist: pytest; extra == "dev"
|
|
26
27
|
Requires-Dist: coverage; extra == "dev"
|
|
27
28
|
Requires-Dist: pymarkdownlnt; extra == "dev"
|
|
@@ -50,7 +51,7 @@ Classes to add key prefix and stats to
|
|
|
50
51
|
and other cache-related utils.
|
|
51
52
|
|
|
52
53
|

|
|
53
|
-

|
|
54
55
|

|
|
55
56
|

|
|
56
57
|

|
|
@@ -74,12 +75,13 @@ with `cachetools`.
|
|
|
74
75
|
class for Memcached.
|
|
75
76
|
- `DictCache` a very simple `dict` cache.
|
|
76
77
|
|
|
77
|
-
###
|
|
78
|
+
### Wrappers to extend cache capabilities
|
|
78
79
|
|
|
79
80
|
- `PrefixedCache`, `PrefixedMemCached` and `PrefixedRedisCache` add a prefix to
|
|
80
81
|
distinguish sources on a shared cache.
|
|
81
|
-
- `StatsCache`, `
|
|
82
|
-
to report the cache hit rate
|
|
82
|
+
- `StatsCache`, `MemCached` and `RedisCache` add a `hits` method
|
|
83
|
+
to report the cache hit rate, `stats` to report statistics and
|
|
84
|
+
`reset` to reset statistics.
|
|
83
85
|
- `LockedCache` use a (thread) lock to control cache accesses.
|
|
84
86
|
- `TwoLevelCache` allows to combine two caches.
|
|
85
87
|
- `DebugCache` to trace cache calls using `logging`.
|
|
@@ -90,6 +92,14 @@ with `cachetools`.
|
|
|
90
92
|
function result is in cache, and to delete such an entry.
|
|
91
93
|
- `cacheFunctions` and `cacheMethods`: add caching to functions or methods.
|
|
92
94
|
|
|
95
|
+
## License
|
|
96
|
+
|
|
97
|
+
This code is [Public Domain](https://creativecommons.org/publicdomain/zero/1.0/).
|
|
98
|
+
|
|
99
|
+
All software has bug, this is software, hence… Beware that you may lose your
|
|
100
|
+
hairs or your friends because of it. If you like it, feel free to send a
|
|
101
|
+
postcard to the author.
|
|
102
|
+
|
|
93
103
|
## More
|
|
94
104
|
|
|
95
105
|
See the
|
|
@@ -98,7 +108,3 @@ See the
|
|
|
98
108
|
[issues](https://github.com/zx80/cachetools-utils/issues) on GitHub.
|
|
99
109
|
|
|
100
110
|
See [packages](https://pypi.org/project/CacheToolsUtils/) on PyPI.
|
|
101
|
-
|
|
102
|
-
## License
|
|
103
|
-
|
|
104
|
-
This code is public domain.
|
|
@@ -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
|

|
|
@@ -31,12 +31,13 @@ with `cachetools`.
|
|
|
31
31
|
class for Memcached.
|
|
32
32
|
- `DictCache` a very simple `dict` cache.
|
|
33
33
|
|
|
34
|
-
###
|
|
34
|
+
### Wrappers to extend cache capabilities
|
|
35
35
|
|
|
36
36
|
- `PrefixedCache`, `PrefixedMemCached` and `PrefixedRedisCache` add a prefix to
|
|
37
37
|
distinguish sources on a shared cache.
|
|
38
|
-
- `StatsCache`, `
|
|
39
|
-
to report the cache hit rate
|
|
38
|
+
- `StatsCache`, `MemCached` and `RedisCache` add a `hits` method
|
|
39
|
+
to report the cache hit rate, `stats` to report statistics and
|
|
40
|
+
`reset` to reset statistics.
|
|
40
41
|
- `LockedCache` use a (thread) lock to control cache accesses.
|
|
41
42
|
- `TwoLevelCache` allows to combine two caches.
|
|
42
43
|
- `DebugCache` to trace cache calls using `logging`.
|
|
@@ -47,6 +48,14 @@ with `cachetools`.
|
|
|
47
48
|
function result is in cache, and to delete such an entry.
|
|
48
49
|
- `cacheFunctions` and `cacheMethods`: add caching to functions or methods.
|
|
49
50
|
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
This code is [Public Domain](https://creativecommons.org/publicdomain/zero/1.0/).
|
|
54
|
+
|
|
55
|
+
All software has bug, this is software, hence… Beware that you may lose your
|
|
56
|
+
hairs or your friends because of it. If you like it, feel free to send a
|
|
57
|
+
postcard to the author.
|
|
58
|
+
|
|
50
59
|
## More
|
|
51
60
|
|
|
52
61
|
See the
|
|
@@ -55,7 +64,3 @@ See the
|
|
|
55
64
|
[issues](https://github.com/zx80/cachetools-utils/issues) on GitHub.
|
|
56
65
|
|
|
57
66
|
See [packages](https://pypi.org/project/CacheToolsUtils/) on PyPI.
|
|
58
|
-
|
|
59
|
-
## License
|
|
60
|
-
|
|
61
|
-
This code is public domain.
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "CacheToolsUtils"
|
|
7
|
-
version = "
|
|
7
|
+
version = "9.0"
|
|
8
8
|
authors = [ { name = "Fabien Coelho", email = "cachetools.utils@coelho.net" } ]
|
|
9
9
|
description = "Cachetools Utilities"
|
|
10
10
|
readme = "README.md"
|
|
@@ -30,7 +30,7 @@ package = "https://pypi.org/project/CacheToolsUtils/"
|
|
|
30
30
|
py-modules = [ "CacheToolsUtils" ]
|
|
31
31
|
|
|
32
32
|
[project.optional-dependencies]
|
|
33
|
-
dev = [ "mypy", "pyright", "black", "flake8", "pytest", "coverage", "pymarkdownlnt", "types-redis", "types-cachetools" ]
|
|
33
|
+
dev = [ "mypy", "pyright", "black", "flake8", "ruff", "pytest", "coverage", "pymarkdownlnt", "types-redis", "types-cachetools" ]
|
|
34
34
|
doc = [ "sphinx", "sphinx_rtd_theme", "sphinx-autoapi", "sphinx-lint", "myst_parser" ]
|
|
35
35
|
tests = [ "pymemcache", "redis" ]
|
|
36
36
|
pub = [ "build", "wheel", "twine" ]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|