Skip to content

Commit 8415ab9

Browse files
committed
fix: handle KeyError in LRUTrieCache move_to_end method
- Added error handling for KeyError when moving items to the end of the LRU cache. - If the key is not found, it initializes the key with None and then moves it to the end, followed by eviction of the least recently used item.
1 parent 7e75f9f commit 8415ab9

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

src/art/tinker/prefix_cache.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,12 @@ def lookup(self, rendered_tokens: Sequence[int]) -> PrefixEntry | None:
4141
if match is None:
4242
return None
4343
match_key, entry = match
44-
self._lru.move_to_end(match_key)
44+
try:
45+
self._lru.move_to_end(match_key)
46+
except KeyError:
47+
self._lru[match_key] = None
48+
self._lru.move_to_end(match_key)
49+
self._evict()
4550
return entry
4651

4752
def insert(self, rendered_prefix: Sequence[int], raw_prefix: Sequence[int]) -> None:

0 commit comments

Comments
 (0)