cachetools 2.1.0

This commit is contained in:
Jay Lee
2018-07-04 19:51:43 -04:00
parent 26ebf30da7
commit 518e506df4
7 changed files with 39 additions and 25 deletions

View File

@@ -2,16 +2,25 @@ from __future__ import absolute_import
import random
from .cache import Cache
from .cache import Cache, _deprecated
# random.choice cannot be pickled in Python 2.7
def _choice(seq):
return random.choice(seq)
class RRCache(Cache):
"""Random Replacement (RR) cache implementation."""
def __init__(self, maxsize, choice=random.choice, missing=None,
def __init__(self, maxsize, choice=random.choice, missing=_deprecated,
getsizeof=None):
Cache.__init__(self, maxsize, missing, getsizeof)
self.__choice = choice
# TODO: use None as default, assing to self.choice directly?
if choice is random.choice:
self.__choice = _choice
else:
self.__choice = choice
@property
def choice(self):