| 40 | raise MissCacheError() |
| 41 | |
| 42 | def add(self, key: Hashable, value: Any) -> None: |
| 43 | with self.lock(): |
| 44 | if key in self.fixed_cache: |
| 45 | l = self.fixed_cache[key] |
| 46 | if len(l) < self.list_size and value not in l: |
| 47 | l.append(value) |
| 48 | elif key in self.cache: |
| 49 | self.cache.move_to_end(key) |
| 50 | l = self.cache[key] |
| 51 | if len(l) < self.list_size and value not in l: |
| 52 | l.append(value) |
| 53 | else: |
| 54 | if len(self.cache) >= self.cache_size: |
| 55 | self.cache.popitem(last=False) |
| 56 | self.cache[key] = [value] |
| 57 | |
| 58 | @contextmanager |
| 59 | def lock(self): |