@@ -115,36 +115,6 @@ def __init__(self, request_executor: RequestExecutor, commands: List[GetRequest]
115115 def create_request (self , node : ServerNode ) -> Optional [requests .Request ]:
116116 self .__base_url = f"{ node .url } /databases/{ node .database } "
117117 url = self .__base_url + "/multi_get"
118- # todo: aggressive caching
119- # if self.__maybe_read_all_from_cache(self.__request_executor.aggressive_caching):
120- # self.aggressively_cached = True
121- # return None
122- #
123- # aggressive_cache_options: AggressiveCacheOptions = self.__request_executor.aggressive_caching
124- # if aggressive_cache_options and aggressive_cache_options.mode == AggressiveCacheMode.TRACK_CHANGES:
125- # self.result = []
126- # for command in self.__commands:
127- # if not command.can_cache_aggressively:
128- # break
129- # cache_key = self.__get_cache_key(command)[0]
130- # cached_item, _, cached_ref = self.__http_cache.get(cache_key, "", "")
131- # cached_item: ReleaseCacheItem
132- # if (
133- # cached_ref is None
134- # or cached_item.age > aggressive_cache_options.duration
135- # or cached_item.might_have_been_modified
136- # ):
137- # break
138- # get_response = GetResponse()
139- # get_response.result = cached_ref
140- # get_response.status_code = http.HTTPStatus.NOT_MODIFIED
141- # self.result.append(get_response)
142- #
143- # if len(self.result) == len(self.__commands):
144- # return None
145- #
146- # self.result = None
147-
148118 request = requests .Request ("POST" , url )
149119
150120 request .data = {
@@ -211,7 +181,6 @@ def __get_cache_key(self, command: GetRequest) -> (str, str):
211181 req_url = self .__base_url + command .url_and_query
212182 return command .method + "-" + req_url if command .method else req_url , req_url
213183
214- # todo: make sure json parses correctly down there
215184 def set_response_raw (self , response : requests .Response , stream : bytes ) -> None :
216185 try :
217186 try :
@@ -224,7 +193,7 @@ def set_response_raw(self, response: requests.Response, stream: bytes) -> None:
224193
225194 for get_response in self .read_responses (response_temp ):
226195 command = self .__commands [i ]
227- self .__maybe_set_cache (get_response , command )
196+ self .__maybe_set_cache (get_response , command , i )
228197
229198 if self .__cached is not None and get_response .status_code == http .HTTPStatus .NOT_MODIFIED :
230199 cloned_response = GetResponse ()
@@ -241,8 +210,11 @@ def set_response_raw(self, response: requests.Response, stream: bytes) -> None:
241210 except Exception as e :
242211 self ._throw_invalid_response (e )
243212
244- def __maybe_set_cache (self , get_response : GetResponse , command : GetRequest ):
213+ def __maybe_set_cache (self , get_response : GetResponse , command : GetRequest , cached_index : int ):
245214 if get_response .status_code == http .HTTPStatus .NOT_MODIFIED :
215+ # if not modified - update age
216+ if self .__cached is not None :
217+ self .__cached .values [cached_index ][0 ].not_modified ()
246218 return
247219
248220 cache_key = self .__get_cache_key (command )[0 ]
@@ -281,7 +253,19 @@ def is_read_request(self) -> bool:
281253 return False
282254
283255 def close_cache (self ):
256+ # If _cached is not null - it means that the client approached with this multitask request to node
257+ # and the request failed and now client tries to send it to another node.
258+
284259 if self .__cached is not None :
285260 self .__cached .close ()
286261
287262 self .__cached = None
263+ # The client sends the commands.
264+ # Some of which could be saved in cache with a response
265+ # that includes the change vector that received from the old fallen node.
266+ # The client can't use those responses because their URLs are different
267+ # (include the IP and port of the old node), because of that the client
268+ # needs to get those docs again from the new node.
269+
270+ for command in self .__commands :
271+ command .headers .remove (constants .Headers .IF_NONE_MATCH )
0 commit comments