Mercurial > repos > guerler > hhblits
comparison lib/python3.8/site-packages/pip/_vendor/cachecontrol/cache.py @ 1:64071f2a4cf0 draft default tip
Deleted selected files
| author | guerler |
|---|---|
| date | Mon, 27 Jul 2020 03:55:49 -0400 |
| parents | 9e54283cc701 |
| children |
comparison
equal
deleted
inserted
replaced
| 0:9e54283cc701 | 1:64071f2a4cf0 |
|---|---|
| 1 """ | |
| 2 The cache object API for implementing caches. The default is a thread | |
| 3 safe in-memory dictionary. | |
| 4 """ | |
| 5 from threading import Lock | |
| 6 | |
| 7 | |
| 8 class BaseCache(object): | |
| 9 | |
| 10 def get(self, key): | |
| 11 raise NotImplementedError() | |
| 12 | |
| 13 def set(self, key, value): | |
| 14 raise NotImplementedError() | |
| 15 | |
| 16 def delete(self, key): | |
| 17 raise NotImplementedError() | |
| 18 | |
| 19 def close(self): | |
| 20 pass | |
| 21 | |
| 22 | |
| 23 class DictCache(BaseCache): | |
| 24 | |
| 25 def __init__(self, init_dict=None): | |
| 26 self.lock = Lock() | |
| 27 self.data = init_dict or {} | |
| 28 | |
| 29 def get(self, key): | |
| 30 return self.data.get(key, None) | |
| 31 | |
| 32 def set(self, key, value): | |
| 33 with self.lock: | |
| 34 self.data.update({key: value}) | |
| 35 | |
| 36 def delete(self, key): | |
| 37 with self.lock: | |
| 38 if key in self.data: | |
| 39 self.data.pop(key) |
