cachetools 6.2.0__tar.gz → 6.2.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.
- {cachetools-6.2.0 → cachetools-6.2.2}/CHANGELOG.rst +18 -0
- {cachetools-6.2.0/src/cachetools.egg-info → cachetools-6.2.2}/PKG-INFO +4 -1
- {cachetools-6.2.0 → cachetools-6.2.2}/README.rst +2 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/docs/index.rst +49 -5
- {cachetools-6.2.0 → cachetools-6.2.2}/setup.cfg +1 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools/__init__.py +13 -7
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools/_cached.py +4 -2
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools/func.py +1 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools/keys.py +2 -2
- {cachetools-6.2.0 → cachetools-6.2.2/src/cachetools.egg-info}/PKG-INFO +4 -1
- {cachetools-6.2.0 → cachetools-6.2.2}/LICENSE +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/MANIFEST.in +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/docs/conf.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/pyproject.toml +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/setup.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools/_cachedmethod.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools.egg-info/SOURCES.txt +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools.egg-info/dependency_links.txt +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/src/cachetools.egg-info/top_level.txt +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/__init__.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_cache.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_cached.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_cachedmethod.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_fifo.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_func.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_keys.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_lfu.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_lru.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_rr.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_tlru.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tests/test_ttl.py +0 -0
- {cachetools-6.2.0 → cachetools-6.2.2}/tox.ini +0 -0
|
@@ -1,3 +1,21 @@
|
|
|
1
|
+
v6.2.2 (2025-11-13)
|
|
2
|
+
===================
|
|
3
|
+
|
|
4
|
+
- Minor improvements from GitHub Copilot code review.
|
|
5
|
+
|
|
6
|
+
- Improve documentation.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
v6.2.1 (2025-10-12)
|
|
10
|
+
===================
|
|
11
|
+
|
|
12
|
+
- Add support for Python 3.14.
|
|
13
|
+
|
|
14
|
+
- Improve documentation.
|
|
15
|
+
|
|
16
|
+
- Update CI environment.
|
|
17
|
+
|
|
18
|
+
|
|
1
19
|
v6.2.0 (2025-08-25)
|
|
2
20
|
===================
|
|
3
21
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cachetools
|
|
3
|
-
Version: 6.2.
|
|
3
|
+
Version: 6.2.2
|
|
4
4
|
Summary: Extensible memoizing collections and decorators
|
|
5
5
|
Home-page: https://github.com/tkem/cachetools/
|
|
6
6
|
Author: Thomas Kemmer
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
23
|
Requires-Python: >=3.9
|
|
23
24
|
License-File: LICENSE
|
|
@@ -116,6 +117,7 @@ Related Projects
|
|
|
116
117
|
------------------------------------------------------------------------
|
|
117
118
|
|
|
118
119
|
- asyncache_: Helpers to use cachetools_ with asyncio.
|
|
120
|
+
- cachetools-async_: Helpers to use cachetools_ with asyncio.
|
|
119
121
|
- cacheing_: Pure Python Cacheing Library.
|
|
120
122
|
- CacheToolsUtils_: Stackable cache classes for sharing, encryption,
|
|
121
123
|
statistics *and more* on top of cachetools_, redis_ and memcached_.
|
|
@@ -145,6 +147,7 @@ Licensed under the `MIT License`_.
|
|
|
145
147
|
.. _MIT License: https://raw.github.com/tkem/cachetools/master/LICENSE
|
|
146
148
|
|
|
147
149
|
.. _asyncache: https://pypi.org/project/asyncache/
|
|
150
|
+
.. _cachetools-async: https://pypi.org/project/cachetools-async/
|
|
148
151
|
.. _cacheing: https://pypi.org/project/cacheing/
|
|
149
152
|
.. _CacheToolsUtils: https://pypi.org/project/CacheToolsUtils/
|
|
150
153
|
.. _shelved-cache: https://pypi.org/project/shelved-cache/
|
|
@@ -91,6 +91,7 @@ Related Projects
|
|
|
91
91
|
------------------------------------------------------------------------
|
|
92
92
|
|
|
93
93
|
- asyncache_: Helpers to use cachetools_ with asyncio.
|
|
94
|
+
- cachetools-async_: Helpers to use cachetools_ with asyncio.
|
|
94
95
|
- cacheing_: Pure Python Cacheing Library.
|
|
95
96
|
- CacheToolsUtils_: Stackable cache classes for sharing, encryption,
|
|
96
97
|
statistics *and more* on top of cachetools_, redis_ and memcached_.
|
|
@@ -120,6 +121,7 @@ Licensed under the `MIT License`_.
|
|
|
120
121
|
.. _MIT License: https://raw.github.com/tkem/cachetools/master/LICENSE
|
|
121
122
|
|
|
122
123
|
.. _asyncache: https://pypi.org/project/asyncache/
|
|
124
|
+
.. _cachetools-async: https://pypi.org/project/cachetools-async/
|
|
123
125
|
.. _cacheing: https://pypi.org/project/cacheing/
|
|
124
126
|
.. _CacheToolsUtils: https://pypi.org/project/CacheToolsUtils/
|
|
125
127
|
.. _shelved-cache: https://pypi.org/project/shelved-cache/
|
|
@@ -232,7 +232,7 @@ With :class:`TTLCache` and :class:`TLRUCache`, items may also be
|
|
|
232
232
|
removed after they expire. In this case, :meth:`popitem` will *not*
|
|
233
233
|
be called, but :meth:`expire` will be called from the next mutating
|
|
234
234
|
operation and will return an iterable of the expired `(key, value)`
|
|
235
|
-
pairs. By
|
|
235
|
+
pairs. By overriding :meth:`expire`, a subclass will be able to track
|
|
236
236
|
expired items:
|
|
237
237
|
|
|
238
238
|
.. doctest::
|
|
@@ -350,7 +350,7 @@ often called with the same arguments:
|
|
|
350
350
|
`cache stampede`_ issues under high load, depending on your
|
|
351
351
|
actual use case. Providing a `condition` variable will mitigate
|
|
352
352
|
these situations, but will inflict some performance penalty.
|
|
353
|
-
|
|
353
|
+
|
|
354
354
|
If no separate `lock` parameter is provided, `condition` must also
|
|
355
355
|
implement the `context manager`_ protocol, and will also be used to
|
|
356
356
|
guard access to the cache.
|
|
@@ -451,7 +451,7 @@ often called with the same arguments:
|
|
|
451
451
|
[..., (('fib', 42), 267914296), ..., (('luc', 42), 599074578)]
|
|
452
452
|
|
|
453
453
|
|
|
454
|
-
Function invocations are
|
|
454
|
+
Function invocations are *not* cached if any exceptions are raised.
|
|
455
455
|
To cache some (or all) calls raising exceptions, additional
|
|
456
456
|
function wrappers may be introduced which wrap exceptions as
|
|
457
457
|
regular function results for caching purposes:
|
|
@@ -488,6 +488,49 @@ often called with the same arguments:
|
|
|
488
488
|
print(e, "-", _get_pep_wrapped.cache_info())
|
|
489
489
|
|
|
490
490
|
|
|
491
|
+
Curiously, default function arguments are not quite handled as one
|
|
492
|
+
might expect, and also the use of positional vs. keyword arguments
|
|
493
|
+
may lead to surprising results. In the example below, `foo()`,
|
|
494
|
+
`foo(1)` and `foo(a=1)` are treated as different function
|
|
495
|
+
invocations, with separately cached results:
|
|
496
|
+
|
|
497
|
+
.. doctest::
|
|
498
|
+
:pyversion: >= 3
|
|
499
|
+
|
|
500
|
+
>>> @cached(LRUCache(maxsize=100))
|
|
501
|
+
... def foo(a=1):
|
|
502
|
+
... print(f"foo({a}) called")
|
|
503
|
+
...
|
|
504
|
+
>>> foo()
|
|
505
|
+
foo(1) called
|
|
506
|
+
>>> foo()
|
|
507
|
+
>>> foo(1)
|
|
508
|
+
foo(1) called
|
|
509
|
+
>>> foo(1)
|
|
510
|
+
>>> foo(a=1)
|
|
511
|
+
foo(1) called
|
|
512
|
+
>>> foo(a=1)
|
|
513
|
+
|
|
514
|
+
If consistent behavior is required, a private helper function may
|
|
515
|
+
be introduced to avoid ambiguities, e.g.:
|
|
516
|
+
|
|
517
|
+
.. doctest::
|
|
518
|
+
:pyversion: >= 3
|
|
519
|
+
|
|
520
|
+
>>> def foo(a=1):
|
|
521
|
+
... _foo(a)
|
|
522
|
+
...
|
|
523
|
+
>>> @cached(LRUCache(maxsize=100))
|
|
524
|
+
... def _foo(a):
|
|
525
|
+
... print(f"_foo({a}) called")
|
|
526
|
+
...
|
|
527
|
+
>>> foo()
|
|
528
|
+
_foo(1) called
|
|
529
|
+
>>> foo()
|
|
530
|
+
>>> foo(1)
|
|
531
|
+
>>> foo(a=1)
|
|
532
|
+
|
|
533
|
+
|
|
491
534
|
.. decorator:: cachedmethod(cache, key=cachetools.keys.methodkey, lock=None, condition=None)
|
|
492
535
|
|
|
493
536
|
Decorator to wrap a class or instance method with a memoizing
|
|
@@ -731,8 +774,9 @@ all the decorators in this module are thread-safe by default.
|
|
|
731
774
|
|
|
732
775
|
Decorator to wrap a function with a memoizing callable that saves
|
|
733
776
|
up to `maxsize` results based on a Least Recently Used (LRU)
|
|
734
|
-
algorithm with a per-item time-to-live (TTL) value.
|
|
735
|
-
|
|
777
|
+
algorithm with a per-item time-to-live (TTL) value. By default,
|
|
778
|
+
the time-to-live is set to 600 seconds and :func:`time.monotonic`
|
|
779
|
+
is used to retrieve the current time.
|
|
736
780
|
|
|
737
781
|
.. _@lru_cache: https://docs.python.org/3/library/functools.html#functools.lru_cache
|
|
738
782
|
.. _cache algorithm: https://en.wikipedia.org/wiki/Cache_algorithms
|
|
@@ -12,7 +12,7 @@ __all__ = (
|
|
|
12
12
|
"cachedmethod",
|
|
13
13
|
)
|
|
14
14
|
|
|
15
|
-
__version__ = "6.2.
|
|
15
|
+
__version__ = "6.2.2"
|
|
16
16
|
|
|
17
17
|
import collections
|
|
18
18
|
import collections.abc
|
|
@@ -27,13 +27,13 @@ from . import keys
|
|
|
27
27
|
class _DefaultSize:
|
|
28
28
|
__slots__ = ()
|
|
29
29
|
|
|
30
|
-
def __getitem__(self,
|
|
30
|
+
def __getitem__(self, _key):
|
|
31
31
|
return 1
|
|
32
32
|
|
|
33
|
-
def __setitem__(self,
|
|
34
|
-
|
|
33
|
+
def __setitem__(self, _key, _value):
|
|
34
|
+
pass
|
|
35
35
|
|
|
36
|
-
def pop(self,
|
|
36
|
+
def pop(self, _key):
|
|
37
37
|
return 1
|
|
38
38
|
|
|
39
39
|
|
|
@@ -55,7 +55,7 @@ class Cache(collections.abc.MutableMapping):
|
|
|
55
55
|
|
|
56
56
|
def __repr__(self):
|
|
57
57
|
return "%s(%s, maxsize=%r, currsize=%r)" % (
|
|
58
|
-
self.
|
|
58
|
+
type(self).__name__,
|
|
59
59
|
repr(self.__data),
|
|
60
60
|
self.__maxsize,
|
|
61
61
|
self.__currsize,
|
|
@@ -100,6 +100,12 @@ class Cache(collections.abc.MutableMapping):
|
|
|
100
100
|
def __len__(self):
|
|
101
101
|
return len(self.__data)
|
|
102
102
|
|
|
103
|
+
# Note that we cannot simply inherit get(), pop() and setdefault()
|
|
104
|
+
# from MutableMapping, since these rely on __getitem__ throwing a
|
|
105
|
+
# KeyError on cache miss. This is not the case if __missing__ is
|
|
106
|
+
# implemented for a Cache subclass, so we have to roll our own,
|
|
107
|
+
# somewhat less elegant versions.
|
|
108
|
+
|
|
103
109
|
def get(self, key, default=None):
|
|
104
110
|
if key in self:
|
|
105
111
|
return self[key]
|
|
@@ -642,7 +648,7 @@ class TLRUCache(_TimedCache):
|
|
|
642
648
|
try:
|
|
643
649
|
key = next(iter(self.__items))
|
|
644
650
|
except StopIteration:
|
|
645
|
-
raise KeyError("%s is empty" % self.
|
|
651
|
+
raise KeyError("%s is empty" % type(self).__name__) from None
|
|
646
652
|
else:
|
|
647
653
|
return (key, self.pop(key))
|
|
648
654
|
|
|
@@ -63,7 +63,9 @@ def _locked_info(func, cache, key, lock, info):
|
|
|
63
63
|
v = func(*args, **kwargs)
|
|
64
64
|
with lock:
|
|
65
65
|
try:
|
|
66
|
-
#
|
|
66
|
+
# In case of a race condition, i.e. if another thread
|
|
67
|
+
# stored a value for this key while we were calling
|
|
68
|
+
# func(), prefer the cached value.
|
|
67
69
|
return cache.setdefault(k, v)
|
|
68
70
|
except ValueError:
|
|
69
71
|
return v # value too large
|
|
@@ -173,7 +175,7 @@ def _locked(func, cache, key, lock):
|
|
|
173
175
|
v = func(*args, **kwargs)
|
|
174
176
|
with lock:
|
|
175
177
|
try:
|
|
176
|
-
#
|
|
178
|
+
# possible race condition: see above
|
|
177
179
|
return cache.setdefault(k, v)
|
|
178
180
|
except ValueError:
|
|
179
181
|
return v # value too large
|
|
@@ -92,6 +92,7 @@ def ttl_cache(maxsize=128, ttl=600, timer=time.monotonic, typed=False):
|
|
|
92
92
|
"""Decorator to wrap a function with a memoizing callable that saves
|
|
93
93
|
up to `maxsize` results based on a Least Recently Used (LRU)
|
|
94
94
|
algorithm with a per-item time-to-live (TTL) value.
|
|
95
|
+
|
|
95
96
|
"""
|
|
96
97
|
if maxsize is None:
|
|
97
98
|
return _cache(_UnboundTTLCache(ttl, timer), None, typed)
|
|
@@ -29,8 +29,8 @@ class _HashedTuple(tuple):
|
|
|
29
29
|
return {}
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
#
|
|
33
|
-
#
|
|
32
|
+
# A sentinel for separating args from kwargs. Using the class itself
|
|
33
|
+
# ensures uniqueness and preserves identity when pickling/unpickling.
|
|
34
34
|
_kwmark = (_HashedTuple,)
|
|
35
35
|
|
|
36
36
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: cachetools
|
|
3
|
-
Version: 6.2.
|
|
3
|
+
Version: 6.2.2
|
|
4
4
|
Summary: Extensible memoizing collections and decorators
|
|
5
5
|
Home-page: https://github.com/tkem/cachetools/
|
|
6
6
|
Author: Thomas Kemmer
|
|
@@ -18,6 +18,7 @@ Classifier: Programming Language :: Python :: 3.10
|
|
|
18
18
|
Classifier: Programming Language :: Python :: 3.11
|
|
19
19
|
Classifier: Programming Language :: Python :: 3.12
|
|
20
20
|
Classifier: Programming Language :: Python :: 3.13
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
22
|
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
22
23
|
Requires-Python: >=3.9
|
|
23
24
|
License-File: LICENSE
|
|
@@ -116,6 +117,7 @@ Related Projects
|
|
|
116
117
|
------------------------------------------------------------------------
|
|
117
118
|
|
|
118
119
|
- asyncache_: Helpers to use cachetools_ with asyncio.
|
|
120
|
+
- cachetools-async_: Helpers to use cachetools_ with asyncio.
|
|
119
121
|
- cacheing_: Pure Python Cacheing Library.
|
|
120
122
|
- CacheToolsUtils_: Stackable cache classes for sharing, encryption,
|
|
121
123
|
statistics *and more* on top of cachetools_, redis_ and memcached_.
|
|
@@ -145,6 +147,7 @@ Licensed under the `MIT License`_.
|
|
|
145
147
|
.. _MIT License: https://raw.github.com/tkem/cachetools/master/LICENSE
|
|
146
148
|
|
|
147
149
|
.. _asyncache: https://pypi.org/project/asyncache/
|
|
150
|
+
.. _cachetools-async: https://pypi.org/project/cachetools-async/
|
|
148
151
|
.. _cacheing: https://pypi.org/project/cacheing/
|
|
149
152
|
.. _CacheToolsUtils: https://pypi.org/project/CacheToolsUtils/
|
|
150
153
|
.. _shelved-cache: https://pypi.org/project/shelved-cache/
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|