1
0

Fix LruCache @overload

This commit is contained in:
Eric Eastwood
2025-05-20 13:03:49 -05:00
parent 9943cd39ad
commit f49789bfd0
4 changed files with 18 additions and 9 deletions
+8 -3
View File
@@ -141,7 +141,10 @@ class FederationServer(FederationBase):
# We cache results for transaction with the same ID
self._transaction_resp_cache: ResponseCache[Tuple[str, str]] = ResponseCache(
hs.get_clock(), "fed_txn_handler", timeout_ms=30000
hs.get_clock(),
hs.get_cache_manager(),
"fed_txn_handler",
timeout_ms=30000,
)
self.transaction_actions = TransactionActions(self.store)
@@ -154,13 +157,15 @@ class FederationServer(FederationBase):
ResponseCache(
hs.get_clock(),
hs.get_cache_manager(),
hs.get_cache_manager(),
"state_resp",
timeout_ms=30000,
)
)
self._state_ids_resp_cache: ResponseCache[Tuple[str, str]] = ResponseCache(
hs.get_clock(), hs.get_cache_manager(), "state_ids_resp", timeout_ms=30000
hs.get_clock(),
hs.get_cache_manager(),
"state_ids_resp",
timeout_ms=30000,
)
self._federation_metrics_domains = (
+3 -1
View File
@@ -434,7 +434,9 @@ class ClientIpWorkerStore(ClientIpBackgroundUpdateStore, MonthlyActiveUsersWorke
# (user_id, access_token, ip,) -> last_seen
self.client_ip_last_seen = LruCache[Tuple[str, str, str], int](
cache_name="client_ip_last_seen", max_size=50000
max_size=50000,
cache_name="client_ip_last_seen",
cache_manager=hs.get_cache_manager(),
)
if hs.config.worker.run_background_tasks and self.user_ips_max_age:
+1 -4
View File
@@ -397,15 +397,12 @@ class LruCache(Generic[KT, VT]):
): ...
# If you're *not* providing in the `cache_name`, then you shouldn't provide the
# `cache_manager`
# `cache_manager` or the `metrics_collection_callback`
@overload
def __init__(
self,
max_size: int,
*,
cache_name: Literal[None],
cache_manager: Literal[None],
metrics_collection_callback: Literal[None],
cache_type: Type[Union[dict, TreeCache]] = dict,
size_callback: Optional[Callable[[VT], int]] = None,
apply_cache_factor_from_config: bool = True,
+6 -1
View File
@@ -96,7 +96,12 @@ class LruCacheTestCase(unittest.HomeserverTestCase):
@override_config({"caches": {"per_cache_factors": {"mycache": 10}}})
def test_special_size(self) -> None:
cache: LruCache = LruCache(10, "mycache")
cache: LruCache = LruCache(
10,
cache_name="mycache",
# TODO
# cache_manager=TODO
)
self.assertEqual(cache.max_size, 100)