cachetools 5.3.2__tar.gz → 5.4.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.
Files changed (31) hide show
  1. {cachetools-5.3.2 → cachetools-5.4.0}/CHANGELOG.rst +20 -0
  2. {cachetools-5.3.2 → cachetools-5.4.0}/LICENSE +1 -1
  3. {cachetools-5.3.2/src/cachetools.egg-info → cachetools-5.4.0}/PKG-INFO +5 -3
  4. {cachetools-5.3.2 → cachetools-5.4.0}/README.rst +4 -2
  5. {cachetools-5.3.2 → cachetools-5.4.0}/docs/conf.py +1 -1
  6. {cachetools-5.3.2 → cachetools-5.4.0}/docs/index.rst +21 -5
  7. {cachetools-5.3.2 → cachetools-5.4.0}/src/cachetools/__init__.py +5 -1
  8. {cachetools-5.3.2 → cachetools-5.4.0}/src/cachetools/func.py +4 -0
  9. {cachetools-5.3.2 → cachetools-5.4.0}/src/cachetools/keys.py +6 -1
  10. {cachetools-5.3.2 → cachetools-5.4.0/src/cachetools.egg-info}/PKG-INFO +5 -3
  11. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_cachedmethod.py +25 -26
  12. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_func.py +8 -6
  13. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_mru.py +18 -3
  14. {cachetools-5.3.2 → cachetools-5.4.0}/tox.ini +1 -1
  15. {cachetools-5.3.2 → cachetools-5.4.0}/MANIFEST.in +0 -0
  16. {cachetools-5.3.2 → cachetools-5.4.0}/pyproject.toml +0 -0
  17. {cachetools-5.3.2 → cachetools-5.4.0}/setup.cfg +0 -0
  18. {cachetools-5.3.2 → cachetools-5.4.0}/setup.py +0 -0
  19. {cachetools-5.3.2 → cachetools-5.4.0}/src/cachetools.egg-info/SOURCES.txt +0 -0
  20. {cachetools-5.3.2 → cachetools-5.4.0}/src/cachetools.egg-info/dependency_links.txt +0 -0
  21. {cachetools-5.3.2 → cachetools-5.4.0}/src/cachetools.egg-info/top_level.txt +0 -0
  22. {cachetools-5.3.2 → cachetools-5.4.0}/tests/__init__.py +0 -0
  23. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_cache.py +0 -0
  24. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_cached.py +0 -0
  25. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_fifo.py +0 -0
  26. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_keys.py +0 -0
  27. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_lfu.py +0 -0
  28. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_lru.py +0 -0
  29. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_rr.py +0 -0
  30. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_tlru.py +0 -0
  31. {cachetools-5.3.2 → cachetools-5.4.0}/tests/test_ttl.py +0 -0
@@ -1,3 +1,23 @@
1
+ v5.4.0 (2024-07-15)
2
+ ===================
3
+
4
+ - Add the ``keys.typedmethodkey`` decorator.
5
+
6
+ - Deprecate ``MRUCache`` class.
7
+
8
+ - Deprecate ``@func.mru_cache`` decorator.
9
+
10
+ - Update CI environment.
11
+
12
+
13
+ v5.3.3 (2024-02-26)
14
+ ===================
15
+
16
+ - Documentation improvements.
17
+
18
+ - Update CI environment.
19
+
20
+
1
21
  v5.3.2 (2023-10-24)
2
22
  ===================
3
23
 
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2014-2022 Thomas Kemmer
3
+ Copyright (c) 2014-2024 Thomas Kemmer
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cachetools
3
- Version: 5.3.2
3
+ Version: 5.4.0
4
4
  Summary: Extensible memoizing collections and decorators
5
5
  Home-page: https://github.com/tkem/cachetools/
6
6
  Author: Thomas Kemmer
@@ -116,15 +116,16 @@ Related Projects
116
116
  ------------------------------------------------------------------------
117
117
 
118
118
  - asyncache_: Helpers to use cachetools with async functions
119
+ - cacheing_: Pure Python Cacheing Library
119
120
  - CacheToolsUtils_: Cachetools Utilities
120
- - `kids.cache`_: Kids caching library
121
+ - kids.cache_: Kids caching library
121
122
  - shelved-cache_: Persistent cache for Python cachetools
122
123
 
123
124
 
124
125
  License
125
126
  ------------------------------------------------------------------------
126
127
 
127
- Copyright (c) 2014-2023 Thomas Kemmer.
128
+ Copyright (c) 2014-2024 Thomas Kemmer.
128
129
 
129
130
  Licensed under the `MIT License`_.
130
131
 
@@ -143,6 +144,7 @@ Licensed under the `MIT License`_.
143
144
  .. _MIT License: https://raw.github.com/tkem/cachetools/master/LICENSE
144
145
 
145
146
  .. _asyncache: https://pypi.org/project/asyncache/
147
+ .. _cacheing: https://github.com/breid48/cacheing
146
148
  .. _CacheToolsUtils: https://pypi.org/project/CacheToolsUtils/
147
149
  .. _kids.cache: https://pypi.org/project/kids.cache/
148
150
  .. _shelved-cache: https://pypi.org/project/shelved-cache/
@@ -91,15 +91,16 @@ Related Projects
91
91
  ------------------------------------------------------------------------
92
92
 
93
93
  - asyncache_: Helpers to use cachetools with async functions
94
+ - cacheing_: Pure Python Cacheing Library
94
95
  - CacheToolsUtils_: Cachetools Utilities
95
- - `kids.cache`_: Kids caching library
96
+ - kids.cache_: Kids caching library
96
97
  - shelved-cache_: Persistent cache for Python cachetools
97
98
 
98
99
 
99
100
  License
100
101
  ------------------------------------------------------------------------
101
102
 
102
- Copyright (c) 2014-2023 Thomas Kemmer.
103
+ Copyright (c) 2014-2024 Thomas Kemmer.
103
104
 
104
105
  Licensed under the `MIT License`_.
105
106
 
@@ -118,6 +119,7 @@ Licensed under the `MIT License`_.
118
119
  .. _MIT License: https://raw.github.com/tkem/cachetools/master/LICENSE
119
120
 
120
121
  .. _asyncache: https://pypi.org/project/asyncache/
122
+ .. _cacheing: https://github.com/breid48/cacheing
121
123
  .. _CacheToolsUtils: https://pypi.org/project/CacheToolsUtils/
122
124
  .. _kids.cache: https://pypi.org/project/kids.cache/
123
125
  .. _shelved-cache: https://pypi.org/project/shelved-cache/
@@ -19,7 +19,7 @@ def get_version():
19
19
 
20
20
 
21
21
  project = "cachetools"
22
- copyright = "2014-2023 Thomas Kemmer"
22
+ copyright = "2014-2024 Thomas Kemmer"
23
23
  release, version = get_version()
24
24
 
25
25
  extensions = [
@@ -21,7 +21,6 @@ method calls.
21
21
 
22
22
  .. testsetup:: *
23
23
 
24
- import operator
25
24
  from cachetools import cached, cachedmethod, LRUCache, TLRUCache, TTLCache
26
25
 
27
26
  from unittest import mock
@@ -97,6 +96,12 @@ computed when the item is inserted into the cache.
97
96
  This class discards the most recently used items first to make
98
97
  space when necessary.
99
98
 
99
+ .. deprecated:: 5.4
100
+
101
+ `MRUCache` has been deprecated due to lack of use, to reduce
102
+ maintenance. Please choose another cache implementation that suits
103
+ your needs.
104
+
100
105
  .. autoclass:: RRCache(maxsize, choice=random.choice, getsizeof=None)
101
106
  :members: choice, popitem
102
107
 
@@ -417,12 +422,12 @@ often called with the same arguments:
417
422
 
418
423
  .. testcode::
419
424
 
420
- class CachedPEPs(object):
425
+ class CachedPEPs:
421
426
 
422
427
  def __init__(self, cachesize):
423
428
  self.cache = LRUCache(maxsize=cachesize)
424
429
 
425
- @cachedmethod(operator.attrgetter('cache'))
430
+ @cachedmethod(lambda self: self.cache)
426
431
  def get(self, num):
427
432
  """Retrieve text of a Python Enhancement Proposal"""
428
433
  url = 'http://www.python.org/dev/peps/pep-%04d/' % num
@@ -445,7 +450,7 @@ often called with the same arguments:
445
450
 
446
451
  .. testcode::
447
452
 
448
- class CachedReferences(object):
453
+ class CachedReferences:
449
454
 
450
455
  def __init__(self, cachesize):
451
456
  self.cache = LRUCache(maxsize=cachesize)
@@ -492,7 +497,7 @@ functions with the :func:`cached` and :func:`cachedmethod` decorators:
492
497
 
493
498
  .. autofunction:: methodkey
494
499
 
495
- This function is equivalent to :func:`hashkey`, but ignores its
500
+ This function is similar to :func:`hashkey`, but ignores its
496
501
  first positional argument, i.e. `self` when used with the
497
502
  :func:`cachedmethod` decorator.
498
503
 
@@ -503,6 +508,12 @@ functions with the :func:`cached` and :func:`cachedmethod` decorators:
503
508
  ``typedkey(3)`` and ``typedkey(3.0)`` will return different
504
509
  results.
505
510
 
511
+ .. autofunction:: typedmethodkey
512
+
513
+ This function is similar to :func:`typedkey`, but ignores its
514
+ first positional argument, i.e. `self` when used with the
515
+ :func:`cachedmethod` decorator.
516
+
506
517
  These functions can also be helpful when implementing custom key
507
518
  functions for handling some non-hashable arguments. For example,
508
519
  calling the following function with a dictionary as its `env` argument
@@ -599,6 +610,11 @@ all the decorators in this module are thread-safe by default.
599
610
  saves up to `maxsize` results based on a Most Recently Used (MRU)
600
611
  algorithm.
601
612
 
613
+ .. deprecated:: 5.4
614
+
615
+ The `mru_cache` decorator has been deprecated due to lack of use.
616
+ Please choose a decorator based on some other algorithm.
617
+
602
618
  .. decorator:: rr_cache(user_function)
603
619
  rr_cache(maxsize=128, choice=random.choice, typed=False)
604
620
 
@@ -13,7 +13,7 @@ __all__ = (
13
13
  "cachedmethod",
14
14
  )
15
15
 
16
- __version__ = "5.3.2"
16
+ __version__ = "5.4.0"
17
17
 
18
18
  import collections
19
19
  import collections.abc
@@ -241,6 +241,10 @@ class MRUCache(Cache):
241
241
  """Most Recently Used (MRU) cache implementation."""
242
242
 
243
243
  def __init__(self, maxsize, getsizeof=None):
244
+ from warnings import warn
245
+
246
+ warn("MRUCache is deprecated", DeprecationWarning, stacklevel=2)
247
+
244
248
  Cache.__init__(self, maxsize, getsizeof)
245
249
  self.__order = collections.OrderedDict()
246
250
 
@@ -82,6 +82,10 @@ def mru_cache(maxsize=128, typed=False):
82
82
  up to `maxsize` results based on a Most Recently Used (MRU)
83
83
  algorithm.
84
84
  """
85
+ from warnings import warn
86
+
87
+ warn("@mru_cache is deprecated", DeprecationWarning, stacklevel=2)
88
+
85
89
  if maxsize is None:
86
90
  return _cache({}, None, typed)
87
91
  elif callable(maxsize):
@@ -1,6 +1,6 @@
1
1
  """Key functions for memoizing decorators."""
2
2
 
3
- __all__ = ("hashkey", "methodkey", "typedkey")
3
+ __all__ = ("hashkey", "methodkey", "typedkey", "typedmethodkey")
4
4
 
5
5
 
6
6
  class _HashedTuple(tuple):
@@ -55,3 +55,8 @@ def typedkey(*args, **kwargs):
55
55
  key += tuple(type(v) for v in args)
56
56
  key += tuple(type(v) for _, v in sorted(kwargs.items()))
57
57
  return key
58
+
59
+
60
+ def typedmethodkey(self, *args, **kwargs):
61
+ """Return a typed cache key for use with cached methods."""
62
+ return typedkey(*args, **kwargs)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: cachetools
3
- Version: 5.3.2
3
+ Version: 5.4.0
4
4
  Summary: Extensible memoizing collections and decorators
5
5
  Home-page: https://github.com/tkem/cachetools/
6
6
  Author: Thomas Kemmer
@@ -116,15 +116,16 @@ Related Projects
116
116
  ------------------------------------------------------------------------
117
117
 
118
118
  - asyncache_: Helpers to use cachetools with async functions
119
+ - cacheing_: Pure Python Cacheing Library
119
120
  - CacheToolsUtils_: Cachetools Utilities
120
- - `kids.cache`_: Kids caching library
121
+ - kids.cache_: Kids caching library
121
122
  - shelved-cache_: Persistent cache for Python cachetools
122
123
 
123
124
 
124
125
  License
125
126
  ------------------------------------------------------------------------
126
127
 
127
- Copyright (c) 2014-2023 Thomas Kemmer.
128
+ Copyright (c) 2014-2024 Thomas Kemmer.
128
129
 
129
130
  Licensed under the `MIT License`_.
130
131
 
@@ -143,6 +144,7 @@ Licensed under the `MIT License`_.
143
144
  .. _MIT License: https://raw.github.com/tkem/cachetools/master/LICENSE
144
145
 
145
146
  .. _asyncache: https://pypi.org/project/asyncache/
147
+ .. _cacheing: https://github.com/breid48/cacheing
146
148
  .. _CacheToolsUtils: https://pypi.org/project/CacheToolsUtils/
147
149
  .. _kids.cache: https://pypi.org/project/kids.cache/
148
150
  .. _shelved-cache: https://pypi.org/project/shelved-cache/
@@ -1,4 +1,3 @@
1
- import operator
2
1
  import unittest
3
2
 
4
3
  from cachetools import LRUCache, cachedmethod, keys
@@ -9,14 +8,14 @@ class Cached:
9
8
  self.cache = cache
10
9
  self.count = count
11
10
 
12
- @cachedmethod(operator.attrgetter("cache"))
11
+ @cachedmethod(lambda self: self.cache)
13
12
  def get(self, value):
14
13
  count = self.count
15
14
  self.count += 1
16
15
  return count
17
16
 
18
- @cachedmethod(operator.attrgetter("cache"), key=keys.typedkey)
19
- def get_typed(self, value):
17
+ @cachedmethod(lambda self: self.cache, key=keys.typedmethodkey)
18
+ def get_typedmethod(self, value):
20
19
  count = self.count
21
20
  self.count += 1
22
21
  return count
@@ -27,7 +26,7 @@ class Locked:
27
26
  self.cache = cache
28
27
  self.count = 0
29
28
 
30
- @cachedmethod(operator.attrgetter("cache"), lock=lambda self: self)
29
+ @cachedmethod(lambda self: self.cache, lock=lambda self: self)
31
30
  def get(self, value):
32
31
  return self.count
33
32
 
@@ -42,11 +41,11 @@ class Unhashable:
42
41
  def __init__(self, cache):
43
42
  self.cache = cache
44
43
 
45
- @cachedmethod(operator.attrgetter("cache"))
44
+ @cachedmethod(lambda self: self.cache)
46
45
  def get_default(self, value):
47
46
  return value
48
47
 
49
- @cachedmethod(operator.attrgetter("cache"), key=keys.hashkey)
48
+ @cachedmethod(lambda self: self.cache, key=keys.hashkey)
50
49
  def get_hashkey(self, value):
51
50
  return value
52
51
 
@@ -68,16 +67,16 @@ class CachedMethodTest(unittest.TestCase):
68
67
  cached.cache.clear()
69
68
  self.assertEqual(cached.get(1), 2)
70
69
 
71
- def test_typed_dict(self):
70
+ def test_typedmethod_dict(self):
72
71
  cached = Cached(LRUCache(maxsize=2))
73
72
 
74
- self.assertEqual(cached.get_typed(0), 0)
75
- self.assertEqual(cached.get_typed(1), 1)
76
- self.assertEqual(cached.get_typed(1), 1)
77
- self.assertEqual(cached.get_typed(1.0), 2)
78
- self.assertEqual(cached.get_typed(1.0), 2)
79
- self.assertEqual(cached.get_typed(0.0), 3)
80
- self.assertEqual(cached.get_typed(0), 4)
73
+ self.assertEqual(cached.get_typedmethod(0), 0)
74
+ self.assertEqual(cached.get_typedmethod(1), 1)
75
+ self.assertEqual(cached.get_typedmethod(1), 1)
76
+ self.assertEqual(cached.get_typedmethod(1.0), 2)
77
+ self.assertEqual(cached.get_typedmethod(1.0), 2)
78
+ self.assertEqual(cached.get_typedmethod(0.0), 3)
79
+ self.assertEqual(cached.get_typedmethod(0), 4)
81
80
 
82
81
  def test_lru(self):
83
82
  cached = Cached(LRUCache(maxsize=2))
@@ -91,16 +90,16 @@ class CachedMethodTest(unittest.TestCase):
91
90
  cached.cache.clear()
92
91
  self.assertEqual(cached.get(1), 2)
93
92
 
94
- def test_typed_lru(self):
93
+ def test_typedmethod_lru(self):
95
94
  cached = Cached(LRUCache(maxsize=2))
96
95
 
97
- self.assertEqual(cached.get_typed(0), 0)
98
- self.assertEqual(cached.get_typed(1), 1)
99
- self.assertEqual(cached.get_typed(1), 1)
100
- self.assertEqual(cached.get_typed(1.0), 2)
101
- self.assertEqual(cached.get_typed(1.0), 2)
102
- self.assertEqual(cached.get_typed(0.0), 3)
103
- self.assertEqual(cached.get_typed(0), 4)
96
+ self.assertEqual(cached.get_typedmethod(0), 0)
97
+ self.assertEqual(cached.get_typedmethod(1), 1)
98
+ self.assertEqual(cached.get_typedmethod(1), 1)
99
+ self.assertEqual(cached.get_typedmethod(1.0), 2)
100
+ self.assertEqual(cached.get_typedmethod(1.0), 2)
101
+ self.assertEqual(cached.get_typedmethod(0.0), 3)
102
+ self.assertEqual(cached.get_typedmethod(0), 4)
104
103
 
105
104
  def test_nospace(self):
106
105
  cached = Cached(LRUCache(maxsize=0))
@@ -142,10 +141,10 @@ class CachedMethodTest(unittest.TestCase):
142
141
  self.assertEqual(cached.get(1), 2)
143
142
  self.assertEqual(cached.get(1.0), 2)
144
143
 
145
- ref = cached.get_typed(1)
144
+ ref = cached.get_typedmethod(1)
146
145
  self.assertEqual(ref, 3)
147
- self.assertEqual(cached.get_typed(1), 3)
148
- self.assertEqual(cached.get_typed(1.0), 4)
146
+ self.assertEqual(cached.get_typedmethod(1), 3)
147
+ self.assertEqual(cached.get_typedmethod(1.0), 4)
149
148
 
150
149
  cached.cache.clear()
151
150
  self.assertEqual(cached.get(1), 5)
@@ -100,30 +100,32 @@ class DecoratorTestMixin:
100
100
 
101
101
 
102
102
  class FIFODecoratorTest(unittest.TestCase, DecoratorTestMixin):
103
-
104
103
  DECORATOR = staticmethod(cachetools.func.fifo_cache)
105
104
 
106
105
 
107
106
  class LFUDecoratorTest(unittest.TestCase, DecoratorTestMixin):
108
-
109
107
  DECORATOR = staticmethod(cachetools.func.lfu_cache)
110
108
 
111
109
 
112
110
  class LRUDecoratorTest(unittest.TestCase, DecoratorTestMixin):
113
-
114
111
  DECORATOR = staticmethod(cachetools.func.lru_cache)
115
112
 
116
113
 
117
114
  class MRUDecoratorTest(unittest.TestCase, DecoratorTestMixin):
115
+ def decorator(self, maxsize, **kwargs):
116
+ import warnings
118
117
 
119
- DECORATOR = staticmethod(cachetools.func.mru_cache)
118
+ with warnings.catch_warnings(record=True) as w:
119
+ warnings.simplefilter("always")
120
+ d = cachetools.func.mru_cache(maxsize, **kwargs)
121
+ self.assertNotEqual(len(w), 0)
122
+ self.assertIs(w[0].category, DeprecationWarning)
123
+ return d
120
124
 
121
125
 
122
126
  class RRDecoratorTest(unittest.TestCase, DecoratorTestMixin):
123
-
124
127
  DECORATOR = staticmethod(cachetools.func.rr_cache)
125
128
 
126
129
 
127
130
  class TTLDecoratorTest(unittest.TestCase, DecoratorTestMixin):
128
-
129
131
  DECORATOR = staticmethod(cachetools.func.ttl_cache)
@@ -1,4 +1,5 @@
1
1
  import unittest
2
+ import warnings
2
3
 
3
4
  from cachetools import MRUCache
4
5
 
@@ -7,10 +8,16 @@ from . import CacheTestMixin
7
8
 
8
9
  class MRUCacheTest(unittest.TestCase, CacheTestMixin):
9
10
 
11
+ # TODO: method to create cache that can be overridden
10
12
  Cache = MRUCache
11
13
 
12
14
  def test_evict__writes_only(self):
13
- cache = MRUCache(maxsize=2)
15
+
16
+ with warnings.catch_warnings(record=True) as w:
17
+ warnings.simplefilter("always")
18
+ cache = MRUCache(maxsize=2)
19
+ self.assertEqual(len(w), 1)
20
+ self.assertIs(w[0].category, DeprecationWarning)
14
21
 
15
22
  cache[1] = 1
16
23
  cache[2] = 2
@@ -22,7 +29,11 @@ class MRUCacheTest(unittest.TestCase, CacheTestMixin):
22
29
  assert 3 in cache
23
30
 
24
31
  def test_evict__with_access(self):
25
- cache = MRUCache(maxsize=2)
32
+ with warnings.catch_warnings(record=True) as w:
33
+ warnings.simplefilter("always")
34
+ cache = MRUCache(maxsize=2)
35
+ self.assertEqual(len(w), 1)
36
+ self.assertIs(w[0].category, DeprecationWarning)
26
37
 
27
38
  cache[1] = 1
28
39
  cache[2] = 2
@@ -34,7 +45,11 @@ class MRUCacheTest(unittest.TestCase, CacheTestMixin):
34
45
  assert 3 in cache
35
46
 
36
47
  def test_evict__with_delete(self):
37
- cache = MRUCache(maxsize=2)
48
+ with warnings.catch_warnings(record=True) as w:
49
+ warnings.simplefilter("always")
50
+ cache = MRUCache(maxsize=2)
51
+ self.assertEqual(len(w), 1)
52
+ self.assertIs(w[0].category, DeprecationWarning)
38
53
 
39
54
  cache[1] = 1
40
55
  cache[2] = 2
@@ -32,7 +32,7 @@ commands =
32
32
  deps =
33
33
  flake8
34
34
  flake8-black; implementation_name == "cpython"
35
- black==22.12.0; implementation_name == "cpython"
35
+ black==22.12.0; implementation_name == "cpython" and python_version < "3.8"
36
36
  flake8-bugbear
37
37
  flake8-import-order
38
38
  commands =
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