Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit ed2de79

Browse files
committedOct 25, 2019
#1577 MAST query result cache support outline
1 parent 6738f84 commit ed2de79

File tree

1 file changed

+21
-5
lines changed

1 file changed

+21
-5
lines changed
 

‎astroquery/mast/core.py

+21-5
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,14 @@ def _fabric_request(self, method, url, params=None, data=None, headers=None,
439439
response.raise_for_status()
440440
return [response]
441441

442+
def _request_w_cache(self, method, url, data=None, headers=None, retrieve_all=True,
443+
cache=False, cache_opts=None):
444+
# TODO: implement caching
445+
# Note: the method only exposes 4 parameters of the underlying _request() function
446+
# to play nice with existing mocks
447+
response = self._request(method, url, data=data, headers=headers, retrieve_all=retrieve_all)
448+
return response
449+
442450
def _request(self, method, url, params=None, data=None, headers=None,
443451
files=None, stream=False, auth=None, retrieve_all=True):
444452
"""
@@ -624,7 +632,7 @@ def logout(self): # pragma: no cover
624632
self._authenticated = False
625633

626634
@class_or_instance
627-
def service_request_async(self, service, params, pagesize=None, page=None, **kwargs):
635+
def service_request_async(self, service, params, pagesize=None, page=None, cache=False, cache_opts=None, **kwargs):
628636
"""
629637
Given a Mashup service and parameters, builds and excecutes a Mashup query.
630638
See documentation `here <https://mast.stsci.edu/api/v0/class_mashup_1_1_mashup_request.html>`__
@@ -644,6 +652,10 @@ def service_request_async(self, service, params, pagesize=None, page=None, **kwa
644652
Default None.
645653
Can be used to override the default behavior of all results being returned to obtain
646654
a specific page of results.
655+
cache : Boolean, optional
656+
try to use cached the query result if set to True
657+
cache_opts : dict, optional
658+
cache options, details TBD, e.g., cache expiration policy, etc.
647659
**kwargs :
648660
See MashupRequest properties
649661
`here <https://mast.stsci.edu/api/v0/class_mashup_1_1_mashup_request.html>`__
@@ -683,8 +695,8 @@ def service_request_async(self, service, params, pagesize=None, page=None, **kwa
683695
mashup_request[prop] = value
684696

685697
req_string = _prepare_service_request_string(mashup_request)
686-
response = self._request("POST", self._MAST_REQUEST_URL, data=req_string, headers=headers,
687-
retrieve_all=retrieve_all)
698+
response = self._request_w_cache("POST", self._MAST_REQUEST_URL, data=req_string, headers=headers,
699+
retrieve_all=retrieve_all, cache=cache, cache_opts=cache_opts)
688700

689701
return response
690702

@@ -1177,7 +1189,7 @@ def query_object_async(self, objectname, radius=0.2*u.deg, pagesize=None, page=N
11771189
return self.query_region_async(coordinates, radius, pagesize, page)
11781190

11791191
@class_or_instance
1180-
def query_criteria_async(self, pagesize=None, page=None, **criteria):
1192+
def query_criteria_async(self, pagesize=None, page=None, cache=False, cache_opts=None, **criteria):
11811193
"""
11821194
Given an set of criteria, returns a list of MAST observations.
11831195
Valid criteria are returned by ``get_metadata("observations")``
@@ -1190,6 +1202,10 @@ def query_criteria_async(self, pagesize=None, page=None, **criteria):
11901202
page : int, optional
11911203
Can be used to override the default behavior of all results being returned to obtain
11921204
one sepcific page of results.
1205+
cache : Boolean, optional
1206+
try to use cached the query result if set to True
1207+
cache_opts : dict, optional
1208+
cache options, details TBD, e.g., cache expiration policy, etc.
11931209
**criteria
11941210
Criteria to apply. At least one non-positional criteria must be supplied.
11951211
Valid criteria are coordinates, objectname, radius (as in `query_region` and `query_object`),
@@ -1274,7 +1290,7 @@ def query_criteria_async(self, pagesize=None, page=None, **criteria):
12741290
params = {"columns": "*",
12751291
"filters": mashup_filters}
12761292

1277-
return self.service_request_async(service, params)
1293+
return self.service_request_async(service, params, cache=cache, cache_opts=cache_opts)
12781294

12791295
def query_region_count(self, coordinates, radius=0.2*u.deg, pagesize=None, page=None):
12801296
"""

0 commit comments

Comments
 (0)
Please sign in to comment.