Skip to content

Commit 016f6b4

Browse files
committed
updates due to feedback
1 parent 6dc09dd commit 016f6b4

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

astroquery/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ class Cache_Conf(_config.ConfigNamespace):
4646

4747
cache_timeout = _config.ConfigItem(
4848
604800,
49-
'Astroquery-wide cache timeout (seconds). Default is 1 week (604800).',
49+
('Astroquery-wide cache timeout (seconds). Default is 1 week (604800). '
50+
'Setting to None prevents the cache from expiring (not recommended).'),
5051
cfgtype='integer'
5152
)
5253

astroquery/query.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def to_cache(response, cache_file):
3535
for key in tuple(response.request.hooks.keys()):
3636
del response.request.hooks[key]
3737
with open(cache_file, "wb") as f:
38-
pickle.dump(response, f)
38+
pickle.dump(response, f, protocol=4)
3939

4040

4141
def _replace_none_iterable(iterable):
@@ -284,7 +284,7 @@ def _request(self, method, url,
284284
somewhere other than `BaseQuery.cache_location`
285285
timeout : int
286286
cache : bool
287-
Override global cache settings.
287+
Optional, if specified, overrides global cache settings.
288288
verify : bool
289289
Verify the server's TLS certificate?
290290
(see http://docs.python-requests.org/en/master/_modules/requests/sessions/?highlight=verify)

astroquery/tests/test_cache.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,13 +167,20 @@ def test_timeout(monkeypatch):
167167
assert resp.content == TEXT1
168168

169169
# Changing the file date so the cache will consider it expired
170-
cache_file = list(mytest.cache_location.iterdir())[0]
170+
cache_file = next(mytest.cache_location.iterdir())
171171
modTime = mktime(datetime(1970, 1, 1).timetuple())
172172
os.utime(cache_file, (modTime, modTime))
173-
173+
174174
resp = mytest.test_func(URL1)
175175
assert resp.content == TEXT2 # now see the new response
176176

177+
# Testing a cache timeout of "none"
178+
cache_conf.cache_timeout = None
179+
set_response(TEXT1)
180+
181+
resp = mytest.test_func(URL1)
182+
assert resp.content == TEXT2 # cache is accessed
183+
177184

178185
def test_deactivate():
179186
cache_conf.reset()

docs/index.rst

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,17 +195,15 @@ Shown here are the cache properties, using Simbad as an example:
195195
196196
>>> from astroquery import cache_conf
197197
>>> from astroquery.simbad import Simbad
198-
198+
...
199199
>>> # Is the cache active?
200200
>>> print(cache_conf.cache_active)
201201
True
202-
203202
>>> # Cache timout in seconds
204203
>>> print(cache_conf.cache_timeout)
205204
604800
206-
207205
>>> # Cache location
208-
>>> print(Simbad.cache_location)
206+
>>> print(Simbad.cache_location) # doctest: +IGNORE_OUTPUT
209207
/Users/username/.astropy/cache/astroquery/Simbad
210208
211209

0 commit comments

Comments
 (0)