mirror of
https://github.com/beetbox/beets.git
synced 2026-02-12 18:31:48 +01:00
Refine @cached decorator from #3258
Don't restrict to Python 2 precisely.
This commit is contained in:
parent
d236e1edff
commit
ff1d43ddf9
1 changed files with 7 additions and 4 deletions
|
|
@ -554,12 +554,15 @@ def _parse(template):
|
|||
return Expression(parts)
|
||||
|
||||
|
||||
# Decorator that enables lru_cache on py3, and no caching on py2.
|
||||
def cached(func):
|
||||
if six.PY2:
|
||||
# Sorry python2 users, no caching for you :(
|
||||
"""Like the `functools.lru_cache` decorator, but works (as a no-op)
|
||||
on Python < 3.2.
|
||||
"""
|
||||
if hasattr(functools, 'lru_cache'):
|
||||
return functools.lru_cache(maxsize=128)(func)
|
||||
else:
|
||||
# Do nothing when lru_cache is not available.
|
||||
return func
|
||||
return functools.lru_cache(maxsize=128)(func)
|
||||
|
||||
|
||||
@cached
|
||||
|
|
|
|||
Loading…
Reference in a new issue