12
12
13
13
import asyncio
14
14
import json
15
- import time
16
15
from collections .abc import Callable , Iterable
17
16
from functools import partial
18
17
from logging import Logger
19
18
from typing import Any , cast
20
19
21
20
from .common import IPC_FOLDER , MINIMUM_ADDR_LEN , get_logger
22
- from .types import ClientInfo , JSONResponse , MonitorInfo , PyprError , RetensionTimes
23
- from .utils import CacheData
21
+ from .types import ClientInfo , JSONResponse , MonitorInfo , PyprError
24
22
25
23
log : Logger | None = None
26
24
@@ -43,9 +41,6 @@ async def get_event_stream() -> tuple[asyncio.StreamReader, asyncio.StreamWriter
43
41
return await asyncio .open_unix_connection (EVENTS )
44
42
45
43
46
- # Hyprctl JSON : cached responses {{{
47
-
48
-
49
44
def retry_on_reset (func : Callable ) -> Callable :
50
45
"""Retry on reset wrapper."""
51
46
@@ -64,14 +59,6 @@ async def wrapper(*args, logger: Logger, **kwargs) -> Any: # noqa: ANN401
64
59
return wrapper
65
60
66
61
67
- cached_responses : dict [str , CacheData ] = {
68
- # <command name>: CacheData
69
- "monitors" : CacheData (retension_time = RetensionTimes .LONG ),
70
- "workspaces" : CacheData (retension_time = RetensionTimes .SHORT ),
71
- "clients" : CacheData (retension_time = RetensionTimes .SHORT ),
72
- }
73
-
74
-
75
62
async def _get_response (command : bytes , logger : Logger ) -> JSONResponse :
76
63
"""Get response of `command` from the IPC socket."""
77
64
try :
@@ -93,20 +80,8 @@ async def _get_response(command: bytes, logger: Logger) -> JSONResponse:
93
80
async def hyprctl_json (command : str , logger : Logger | None = None ) -> JSONResponse :
94
81
"""Run an IPC command and return the JSON output."""
95
82
logger = cast (Logger , logger or log )
96
- now = time .time ()
97
- cache_data : CacheData | None = cached_responses .get (command )
98
- if cache_data and cache_data .expiration_date > now :
99
- logger .debug ("%s (CACHE HIT)" , command )
100
- return await cache_data .wait_update ()
101
-
102
- logger .debug (command )
103
- if cache_data : # should fill the cache
104
- cache_data .set_pending (ref_time = now )
105
-
106
83
ret = await _get_response (f"-j/{ command } " .encode (), logger )
107
84
assert isinstance (ret , list | dict )
108
- if cache_data :
109
- cache_data .set_value (ret )
110
85
return ret
111
86
112
87
0 commit comments