Use FIFOCache.

Related comments: https://github.com/Textualize/textual/pull/2604#discussion_r1202431626
This commit is contained in:
Rodrigo Girão Serrão
2023-05-23 15:32:49 +01:00
parent 239e5eebc6
commit 3308cdde1c

View File

@@ -4,6 +4,7 @@ from abc import ABC, abstractmethod
from dataclasses import dataclass
from typing import Iterable
from ._cache import FIFOCache
from .dom import DOMNode
from .message import Message
@@ -26,7 +27,7 @@ class Suggester(ABC):
See [`SuggestFromList`][textual.suggester.SuggestFromList] for an example.
"""
cache: dict[str, str | None] | None
cache: FIFOCache[str, str | None] | None
"""Suggestion cache, if used."""
def __init__(self, use_cache: bool = True):
@@ -35,7 +36,7 @@ class Suggester(ABC):
Args:
use_cache: Whether to cache suggestion results.
"""
self.cache = {} if use_cache else None
self.cache = FIFOCache(1024) if use_cache else None
async def _get_suggestion(self, requester: DOMNode, value: str) -> None:
"""Used by widgets to get completion suggestions.