(self, *, loop, max_size, on_remove, max_lifetime)
| 2538 | '_max_lifetime') |
| 2539 | |
| 2540 | def __init__(self, *, loop, max_size, on_remove, max_lifetime): |
| 2541 | self._loop = loop |
| 2542 | self._max_size = max_size |
| 2543 | self._on_remove = on_remove |
| 2544 | self._max_lifetime = max_lifetime |
| 2545 | |
| 2546 | # We use an OrderedDict for LRU implementation. Operations: |
| 2547 | # |
| 2548 | # * We use a simple `__setitem__` to push a new entry: |
| 2549 | # `entries[key] = new_entry` |
| 2550 | # That will push `new_entry` to the *end* of the entries dict. |
| 2551 | # |
| 2552 | # * When we have a cache hit, we call |
| 2553 | # `entries.move_to_end(key, last=True)` |
| 2554 | # to move the entry to the *end* of the entries dict. |
| 2555 | # |
| 2556 | # * When we need to remove entries to maintain `max_size`, we call |
| 2557 | # `entries.popitem(last=False)` |
| 2558 | # to remove an entry from the *beginning* of the entries dict. |
| 2559 | # |
| 2560 | # So new entries and hits are always promoted to the end of the |
| 2561 | # entries dict, whereas the unused one will group in the |
| 2562 | # beginning of it. |
| 2563 | self._entries = collections.OrderedDict() |
| 2564 | |
| 2565 | def __len__(self): |
| 2566 | return len(self._entries) |
nothing calls this directly
no outgoing calls
no test coverage detected