Skip to content

Commit

Permalink
Fix #256: Deprecate @mru_cache decorator.
Browse files Browse the repository at this point in the history
  • Loading branch information
tkem committed Jul 15, 2024
1 parent f461c73 commit f9021d5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 5 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -604,6 +604,11 @@ all the decorators in this module are thread-safe by default.
saves up to `maxsize` results based on a Most Recently Used (MRU)
algorithm.

.. deprecated:: 5.4

The `mru_cache` decorator has been deprecated due to lack of use.
Please choose a decorator based on some other algorithm.

.. decorator:: rr_cache(user_function)
rr_cache(maxsize=128, choice=random.choice, typed=False)

Expand Down
4 changes: 4 additions & 0 deletions src/cachetools/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ def mru_cache(maxsize=128, typed=False):
up to `maxsize` results based on a Most Recently Used (MRU)
algorithm.
"""
from warnings import warn

warn("@mru_cache is deprecated", DeprecationWarning, stacklevel=2)

if maxsize is None:
return _cache({}, None, typed)
elif callable(maxsize):
Expand Down
14 changes: 8 additions & 6 deletions tests/test_func.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,30 +100,32 @@ def __eq__(self, other):


class FIFODecoratorTest(unittest.TestCase, DecoratorTestMixin):

DECORATOR = staticmethod(cachetools.func.fifo_cache)


class LFUDecoratorTest(unittest.TestCase, DecoratorTestMixin):

DECORATOR = staticmethod(cachetools.func.lfu_cache)


class LRUDecoratorTest(unittest.TestCase, DecoratorTestMixin):

DECORATOR = staticmethod(cachetools.func.lru_cache)


class MRUDecoratorTest(unittest.TestCase, DecoratorTestMixin):
def decorator(self, maxsize, **kwargs):
import warnings

DECORATOR = staticmethod(cachetools.func.mru_cache)
with warnings.catch_warnings(record=True) as w:
warnings.simplefilter("always")
d = cachetools.func.mru_cache(maxsize, **kwargs)
self.assertEqual(len(w), 1)
self.assertIs(w[0].category, DeprecationWarning)
return d


class RRDecoratorTest(unittest.TestCase, DecoratorTestMixin):

DECORATOR = staticmethod(cachetools.func.rr_cache)


class TTLDecoratorTest(unittest.TestCase, DecoratorTestMixin):

DECORATOR = staticmethod(cachetools.func.ttl_cache)

0 comments on commit f9021d5

Please sign in to comment.