(self, *, loop, max_size, on_remove, max_lifetime)
| 2483 | '_max_lifetime') |
| 2484 | |
| 2485 | def __init__(self, *, loop, max_size, on_remove, max_lifetime): |
| 2486 | self._loop = loop |
| 2487 | self._max_size = max_size |
| 2488 | self._on_remove = on_remove |
| 2489 | self._max_lifetime = max_lifetime |
| 2490 | |
| 2491 | # We use an OrderedDict for LRU implementation. Operations: |
| 2492 | # |
| 2493 | # * We use a simple `__setitem__` to push a new entry: |
| 2494 | # `entries[key] = new_entry` |
| 2495 | # That will push `new_entry` to the *end* of the entries dict. |
| 2496 | # |
| 2497 | # * When we have a cache hit, we call |
| 2498 | # `entries.move_to_end(key, last=True)` |
| 2499 | # to move the entry to the *end* of the entries dict. |
| 2500 | # |
| 2501 | # * When we need to remove entries to maintain `max_size`, we call |
| 2502 | # `entries.popitem(last=False)` |
| 2503 | # to remove an entry from the *beginning* of the entries dict. |
| 2504 | # |
| 2505 | # So new entries and hits are always promoted to the end of the |
| 2506 | # entries dict, whereas the unused one will group in the |
| 2507 | # beginning of it. |
| 2508 | self._entries = collections.OrderedDict() |
| 2509 | |
| 2510 | def __len__(self): |
| 2511 | return len(self._entries) |
nothing calls this directly
no outgoing calls
no test coverage detected