Speed up singleton decorator so it can be used more places (#116292)

This commit is contained in:
J. Nick Koston 2024-04-28 12:11:08 -05:00 committed by GitHub
parent 48b1678075
commit ab2ea6100c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 25 additions and 28 deletions

View file

@ -25,6 +25,7 @@ def singleton(data_key: str) -> Callable[[_FuncType[_T]], _FuncType[_T]]:
"""Wrap a function with caching logic."""
if not asyncio.iscoroutinefunction(func):
@functools.lru_cache(maxsize=1)
@bind_hass
@functools.wraps(func)
def wrapped(hass: HomeAssistant) -> _T: