Get an item from the cache. Moves the item up so that it has the highest priority then. Raise a `KeyError` if it does not exist.
(self, key)
| 390 | ) |
| 391 | |
| 392 | def __getitem__(self, key): |
| 393 | """Get an item from the cache. Moves the item up so that it has the |
| 394 | highest priority then. |
| 395 | |
| 396 | Raise a `KeyError` if it does not exist. |
| 397 | """ |
| 398 | self._wlock.acquire() |
| 399 | try: |
| 400 | rv = self._mapping[key] |
| 401 | if self._queue[-1] != key: |
| 402 | try: |
| 403 | self._remove(key) |
| 404 | except ValueError: |
| 405 | # if something removed the key from the container |
| 406 | # when we read, ignore the ValueError that we would |
| 407 | # get otherwise. |
| 408 | pass |
| 409 | self._append(key) |
| 410 | return rv |
| 411 | finally: |
| 412 | self._wlock.release() |
| 413 | |
| 414 | def __setitem__(self, key, value): |
| 415 | """Sets the value for an item. Moves the item up so that it |