Skip to content
Myr

Merge pull request #3909 from sigmavirus24/updates-for-3885

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Update implementation of TimedCache object

authored by Cory Benfield · committed by GitHub · parents 41a33f2, 8e6e47a · Browse files · 1 file+4 added−4 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

1 file+4 added−4 removed

  • other:+4 added−4 removed

1 file+4 added−4 removed

modified:requests/structures.py+4 added-4 removed
146 unmodified lines
147 return '<TimedCache maxlen:%d len:%d expiration_secs:%d>' % \148 (self.maxlen, len(self._dict), self.expiration_secs)149150 def __iter__(self):151 return map(lambda kv: (kv[0], kv[1][1]), self._dict.items()).__iter__()151 return ((key, value[1]) for key, value in self._dict.items())152153 def __delitem__(self, item):154 return self._dict.__delitem__(item)154 del self._dict[item]155156 def __getitem__(self, key):157 """158 Look up an item in the cache. If the item
6 unmodified lines
165 now = int(current_time())166167 if now - occurred > self.expiration_secs:168 del self._dict[key]169 raise KeyError169 raise KeyError(key)170 else:171 return value172173 def __setitem__(self, key, value):
8 unmodified lines
182183 while len(self._dict) >= self.maxlen:184 self._dict.popitem(last=False)185186 return self._dict.__setitem__(key, (now, value))186 self._dict[key] = (now, value)187188 def __len__(self):189 """:return: the length of the cache"""190 return len(self._dict)
4 unmodified lines