···3232 """
3333 return None
34343535+ def count_error_once(self) -> bool:
3636+ """
3737+ When True, only the caller that initiated the external service call
3838+ receives the exception. Subsequent callers that would hit the cached
3939+ error receive None instead.
4040+4141+ Only enable this when ValueT is Optional and None is a safe fallback.
4242+ """
4343+ return False
4444+35453646class ExternalServiceAccessor(Generic[KeyT, ValueT]):
3747 """Facilitates accessing an external service in a way that caches and debounces requests based on a key."""
···8494 try:
8595 cache_entry[0].set(self._service.get_from_service(key))
8696 except Exception as e:
8787- cache_entry[0].set_exception(e)
9797+ if self._service.count_error_once():
9898+ cache_entry[0].set(None)
9999+ else:
100100+ cache_entry[0].set_exception(e)
101101+ raise
8810289103 return cast(ValueT, cache_entry[0].get())
90104