Skip to content

Commit 426d251

Browse files
committed
Return 'cache' property in answer_dict
1 parent 99c793f commit 426d251

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

lib/adapter/adapter.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ def get_page_dict(self, topic, request_options=None):
145145
'topic': topic,
146146
'topic_type': self._adapter_name,
147147
'format': self._get_output_format(topic),
148+
'cache': self._cache_needed,
148149
}
149150
answer_dict.update(answer)
150151

lib/adapter/upstream.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _get_page(self, topic, request_options=None):
5858
+ "?" + options_string
5959
try:
6060
response = requests.get(url, timeout=CONFIG["upstream.timeout"])
61-
answer = response.text
61+
answer = {"cache": False, "answer": response.text}
6262
except requests.exceptions.ConnectionError:
6363
answer = {"cache": False, "answer":_are_you_offline()}
6464
return answer

lib/routing.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,8 @@ def get_answer_dict(self, topic, request_options=None):
182182
}
183183

184184
answer = self._get_page_dict(topic, topic_type, request_options=request_options)
185-
cache.put('q:' + topic, answer)
185+
if answer.get("cache", True):
186+
cache.put('q:' + topic, answer)
186187
return answer
187188

188189
# Try to find cacheable queries in the cache.

0 commit comments

Comments
 (0)