diff --git a/docs/index.rst b/docs/index.rst index 8df4ed9..96893e6 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -96,6 +96,12 @@ computed when the item is inserted into the cache. This class discards the most recently used items first to make space when necessary. + .. deprecated:: 5.4 + + `MRUCache` has been deprecated due to lack of use, to reduce + maintenance. Please choose another cache implementation that suits + your needs. + .. autoclass:: RRCache(maxsize, choice=random.choice, getsizeof=None) :members: choice, popitem diff --git a/src/cachetools/__init__.py b/src/cachetools/__init__.py index 341c1c7..2d4ebed 100644 --- a/src/cachetools/__init__.py +++ b/src/cachetools/__init__.py @@ -241,6 +241,10 @@ class MRUCache(Cache): """Most Recently Used (MRU) cache implementation.""" def __init__(self, maxsize, getsizeof=None): + from warnings import warn + + warn("MRUCache is deprecated", DeprecationWarning, stacklevel=2) + Cache.__init__(self, maxsize, getsizeof) self.__order = collections.OrderedDict() diff --git a/tests/test_func.py b/tests/test_func.py index d375c28..032e839 100644 --- a/tests/test_func.py +++ b/tests/test_func.py @@ -118,7 +118,7 @@ def decorator(self, maxsize, **kwargs): with warnings.catch_warnings(record=True) as w: warnings.simplefilter("always") d = cachetools.func.mru_cache(maxsize, **kwargs) - self.assertEqual(len(w), 1) + self.assertNotEqual(len(w), 0) self.assertIs(w[0].category, DeprecationWarning) return d diff --git a/tests/test_mru.py b/tests/test_mru.py index d11dba4..82c2ac3 100644 --- a/tests/test_mru.py +++ b/tests/test_mru.py @@ -1,4 +1,5 @@ import unittest +import warnings from cachetools import MRUCache @@ -7,10 +8,16 @@ class MRUCacheTest(unittest.TestCase, CacheTestMixin): + # TODO: method to create cache that can be overridden Cache = MRUCache def test_evict__writes_only(self): - cache = MRUCache(maxsize=2) + + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + cache = MRUCache(maxsize=2) + self.assertEqual(len(w), 1) + self.assertIs(w[0].category, DeprecationWarning) cache[1] = 1 cache[2] = 2 @@ -22,7 +29,11 @@ def test_evict__writes_only(self): assert 3 in cache def test_evict__with_access(self): - cache = MRUCache(maxsize=2) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + cache = MRUCache(maxsize=2) + self.assertEqual(len(w), 1) + self.assertIs(w[0].category, DeprecationWarning) cache[1] = 1 cache[2] = 2 @@ -34,7 +45,11 @@ def test_evict__with_access(self): assert 3 in cache def test_evict__with_delete(self): - cache = MRUCache(maxsize=2) + with warnings.catch_warnings(record=True) as w: + warnings.simplefilter("always") + cache = MRUCache(maxsize=2) + self.assertEqual(len(w), 1) + self.assertIs(w[0].category, DeprecationWarning) cache[1] = 1 cache[2] = 2