| Index: client/third_party/cachetools/rr.py
|
| diff --git a/client/third_party/cachetools/rr.py b/client/third_party/cachetools/rr.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8cd856c3727827cbf076c33ff0b65bcc89b7a68c
|
| --- /dev/null
|
| +++ b/client/third_party/cachetools/rr.py
|
| @@ -0,0 +1,28 @@
|
| +from __future__ import absolute_import
|
| +
|
| +import random
|
| +
|
| +from .cache import Cache
|
| +
|
| +
|
| +class RRCache(Cache):
|
| + """Random Replacement (RR) cache implementation."""
|
| +
|
| + def __init__(self, maxsize, choice=random.choice, missing=None,
|
| + getsizeof=None):
|
| + Cache.__init__(self, maxsize, missing, getsizeof)
|
| + self.__choice = choice
|
| +
|
| + @property
|
| + def choice(self):
|
| + """The `choice` function used by the cache."""
|
| + return self.__choice
|
| +
|
| + def popitem(self):
|
| + """Remove and return a random `(key, value)` pair."""
|
| + try:
|
| + key = self.__choice(list(self))
|
| + except IndexError:
|
| + raise KeyError('%s is empty' % self.__class__.__name__)
|
| + else:
|
| + return (key, self.pop(key))
|
|
|