]>
git.proxmox.com Git - ceph.git/blob - ceph/src/pybind/mgr/dashboard/plugins/lru_cache.py
1 # -*- coding: utf-8 -*-
3 This is a minimal implementation of lru_cache function.
5 Based on Python 3 functools and backports.functools_lru_cache.
7 from __future__
import absolute_import
9 from functools
import wraps
10 from collections
import OrderedDict
11 from threading
import RLock
14 def lru_cache(maxsize
=128, typed
=False):
15 if typed
is not False:
16 raise NotImplementedError("typed caching not supported")
18 def decorating_function(function
):
26 "hits={}, misses={}, maxsize={}, currsize={}".format(
27 stats
[0], stats
[1], maxsize
, len(cache
)))
30 def wrapper(*args
, **kwargs
):
31 key
= args
+ tuple(kwargs
.items())
39 ret
= function(*args
, **kwargs
)
40 if len(cache
) == maxsize
:
41 cache
.popitem(last
=False)
47 return decorating_function