1313# See the License for the specific language governing permissions and
1414# limitations under the License.
1515import logging
16- from typing import TYPE_CHECKING , Any , Callable , Dict , Generic , Optional , Set , TypeVar
16+ from typing import TYPE_CHECKING , Any , Callable , Dict , Generic , Optional , TypeVar
1717
1818from twisted .internet import defer
1919
@@ -40,7 +40,6 @@ class ResponseCache(Generic[T]):
4040 def __init__ (self , hs : "HomeServer" , name : str , timeout_ms : float = 0 ):
4141 # Requests that haven't finished yet.
4242 self .pending_result_cache = {} # type: Dict[T, ObservableDeferred]
43- self .pending_conditionals = {} # type: Dict[T, Set[Callable[[Any], bool]]]
4443
4544 self .clock = hs .get_clock ()
4645 self .timeout_sec = timeout_ms / 1000.0
@@ -102,11 +101,7 @@ def set(self, key: T, deferred: defer.Deferred) -> defer.Deferred:
102101 self .pending_result_cache [key ] = result
103102
104103 def remove (r ):
105- should_cache = all (
106- func (r ) for func in self .pending_conditionals .pop (key , [])
107- )
108-
109- if self .timeout_sec and should_cache :
104+ if self .timeout_sec :
110105 self .clock .call_later (
111106 self .timeout_sec , self .pending_result_cache .pop , key , None
112107 )
@@ -117,31 +112,6 @@ def remove(r):
117112 result .addBoth (remove )
118113 return result .observe ()
119114
120- def add_conditional (self , key : T , conditional : Callable [[Any ], bool ]):
121- self .pending_conditionals .setdefault (key , set ()).add (conditional )
122-
123- def wrap_conditional (
124- self ,
125- key : T ,
126- should_cache : Callable [[Any ], bool ],
127- callback : "Callable[..., Any]" ,
128- * args : Any ,
129- ** kwargs : Any
130- ) -> defer .Deferred :
131- """The same as wrap(), but adds a conditional to the final execution.
132-
133- When the final execution completes, *all* conditionals need to return True for it to properly cache,
134- else it'll not be cached in a timed fashion.
135- """
136-
137- # See if there's already a result on this key that hasn't yet completed. Due to the single-threaded nature of
138- # python, adding a key immediately in the same execution thread will not cause a race condition.
139- result = self .get (key )
140- if not result or isinstance (result , defer .Deferred ) and not result .called :
141- self .add_conditional (key , should_cache )
142-
143- return self .wrap (key , callback , * args , ** kwargs )
144-
145115 def wrap (
146116 self , key : T , callback : "Callable[..., Any]" , * args : Any , ** kwargs : Any
147117 ) -> defer .Deferred :
0 commit comments