cachetools 7.3.3__tar.gz → 7.3.4__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-7.3.3 → cachetools-7.3.4}/CHANGELOG.rst +8 -0
- {cachetools-7.3.3/src/cachetools.egg-info → cachetools-7.3.4}/PKG-INFO +1 -1
- {cachetools-7.3.3 → cachetools-7.3.4}/docs/index.rst +10 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/__init__.py +1 -1
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/func.py +9 -5
- {cachetools-7.3.3 → cachetools-7.3.4/src/cachetools.egg-info}/PKG-INFO +1 -1
- {cachetools-7.3.3 → cachetools-7.3.4}/LICENSE +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/MANIFEST.in +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/README.rst +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/docs/conf.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/pyproject.toml +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/setup.cfg +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/__init__.pyi +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/_cached.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/_cachedmethod.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/_descriptor.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/func.pyi +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/keys.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/keys.pyi +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools/py.typed +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools.egg-info/SOURCES.txt +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools.egg-info/dependency_links.txt +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/src/cachetools.egg-info/top_level.txt +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/__init__.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_cache.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_cached.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_cachedmethod.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_classmethod.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_fifo.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_func.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_keys.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_lfu.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_lru.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_rr.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_threading.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_tlru.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tests/test_ttl.py +0 -0
- {cachetools-7.3.3 → cachetools-7.3.4}/tox.ini +0 -0
|
@@ -110,6 +110,12 @@ inserted into the cache.
|
|
|
110
110
|
This class discards the least recently used items first to make
|
|
111
111
|
space when necessary.
|
|
112
112
|
|
|
113
|
+
Retrieving an item via :meth:`LRUCache.__getitem__` marks it as
|
|
114
|
+
most recently used, as does inserting or updating it. Since
|
|
115
|
+
:meth:`items` and :meth:`values` retrieve every item in turn,
|
|
116
|
+
iterating over these views leaves the cache discarding items in
|
|
117
|
+
insertion order.
|
|
118
|
+
|
|
113
119
|
.. autoclass:: RRCache(maxsize, choice=random.choice, getsizeof=None)
|
|
114
120
|
:members: choice, popitem
|
|
115
121
|
|
|
@@ -372,6 +378,10 @@ often called with the same arguments:
|
|
|
372
378
|
condition variable must be created with the corresponding lock,
|
|
373
379
|
e.g. ``condition=threading.Condition(lock)``; an unrelated
|
|
374
380
|
:class:`threading.Condition` will raise :exc:`RuntimeError`.
|
|
381
|
+
On current CPython versions, passing the lock separately this
|
|
382
|
+
way is also slightly faster than providing `condition` alone,
|
|
383
|
+
since acquiring the lock through a :class:`threading.Condition`
|
|
384
|
+
adds Python-level method calls on every cache access.
|
|
375
385
|
|
|
376
386
|
The decorator's `cache`, `key`, `lock` and `condition` parameters
|
|
377
387
|
are also available as :attr:`cache`, :attr:`cache_key`,
|
|
@@ -5,7 +5,7 @@ __all__ = ("fifo_cache", "lfu_cache", "lru_cache", "rr_cache", "ttl_cache")
|
|
|
5
5
|
import math
|
|
6
6
|
import random
|
|
7
7
|
import time
|
|
8
|
-
from threading import Condition
|
|
8
|
+
from threading import Condition, RLock
|
|
9
9
|
|
|
10
10
|
from . import FIFOCache, LFUCache, LRUCache, RRCache, TTLCache, cached, keys
|
|
11
11
|
|
|
@@ -21,11 +21,15 @@ class _UnboundTTLCache(TTLCache):
|
|
|
21
21
|
|
|
22
22
|
def _cache(cache, maxsize, typed):
|
|
23
23
|
def decorator(func):
|
|
24
|
-
#
|
|
25
|
-
#
|
|
26
|
-
#
|
|
24
|
+
# Like functools.lru_cache, this has to be thread-safe. Using
|
|
25
|
+
# a condition variable also prevents cache stampedes. Passing
|
|
26
|
+
# its lock separately skips the Python-level __enter__() and
|
|
27
|
+
# __exit__() methods of Condition on every call.
|
|
27
28
|
key = keys.typedkey if typed else keys.hashkey
|
|
28
|
-
|
|
29
|
+
lock = RLock()
|
|
30
|
+
wrapper = cached(
|
|
31
|
+
cache=cache, key=key, lock=lock, condition=Condition(lock), info=True
|
|
32
|
+
)(func)
|
|
29
33
|
wrapper.cache_parameters = lambda: {"maxsize": maxsize, "typed": typed} # type: ignore
|
|
30
34
|
return wrapper
|
|
31
35
|
|
|
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
|
|
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
|