Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(344)

Side by Side Diff: client/third_party/cachetools/rr.py

Issue 2953253003: Replace custom blob gRPC API with ByteStream (Closed)
Patch Set: Import ndb directly to test code Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « client/third_party/cachetools/lru.py ('k') | client/third_party/cachetools/ttl.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 from __future__ import absolute_import
2
3 import random
4
5 from .cache import Cache
6
7
8 class RRCache(Cache):
9 """Random Replacement (RR) cache implementation."""
10
11 def __init__(self, maxsize, choice=random.choice, missing=None,
12 getsizeof=None):
13 Cache.__init__(self, maxsize, missing, getsizeof)
14 self.__choice = choice
15
16 @property
17 def choice(self):
18 """The `choice` function used by the cache."""
19 return self.__choice
20
21 def popitem(self):
22 """Remove and return a random `(key, value)` pair."""
23 try:
24 key = self.__choice(list(self))
25 except IndexError:
26 raise KeyError('%s is empty' % self.__class__.__name__)
27 else:
28 return (key, self.pop(key))
OLDNEW
« no previous file with comments | « client/third_party/cachetools/lru.py ('k') | client/third_party/cachetools/ttl.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698