@@ -190,14 +190,10 @@ def __init__(self):
190190 .format (vers = version .version ,
191191 olduseragent = S .headers ['User-Agent' ]))
192192
193- self .cache_location = os .path .join (
194- conf .cache_location ,
195- self .__class__ .__name__ .split ("Class" )[0 ])
196- os .makedirs (self .cache_location , exist_ok = True )
197-
198193 self .name = self .__class__ .__name__ .split ("Class" )[0 ]
199- self ._cache_active = conf .use_cache
200- self .cache_timeout = conf .default_cache_timeout
194+
195+
196+ self .reset_cache_preferences ()
201197
202198 def __call__ (self , * args , ** kwargs ):
203199 """ init a fresh copy of self """
@@ -248,11 +244,11 @@ def reset_cache_preferences(self):
248244 """Resets cache preferences to default values"""
249245
250246 self .cache_location = os .path .join (
251- conf .cache_location ,
247+ conf .default_cache_location ,
252248 self .__class__ .__name__ .split ("Class" )[0 ])
253249 os .makedirs (self .cache_location , exist_ok = True )
254250
255- self ._cache_active = conf .use_cache
251+ self .cache_active = conf .default_cache_active
256252 self .cache_timeout = conf .default_cache_timeout
257253
258254 def _request (self , method , url ,
@@ -325,7 +321,7 @@ def _request(self, method, url,
325321 json = json
326322 )
327323
328- if (cache is not False ) and self ._cache_active :
324+ if (cache is not False ) and self .cache_active :
329325 cache = True
330326 else :
331327 cache = False
@@ -349,7 +345,7 @@ def _request(self, method, url,
349345 return local_filepath
350346 else :
351347 query = AstroQuery (method , url , ** req_kwargs )
352- if ((self .cache_location is None ) or (not self ._cache_active ) or (not cache )):
348+ if ((self .cache_location is None ) or (not self .cache_active ) or (not cache )):
353349 with suspend_cache (self ):
354350 response = query .request (self ._session , stream = stream ,
355351 auth = auth , verify = verify ,
@@ -499,12 +495,13 @@ class suspend_cache:
499495
500496 def __init__ (self , obj ):
501497 self .obj = obj
498+ self .original_cache_setting = self .obj .cache_active
502499
503500 def __enter__ (self ):
504- self .obj ._cache_active = False
501+ self .obj .cache_active = False
505502
506503 def __exit__ (self , exc_type , exc_value , traceback ):
507- self .obj ._cache_active = True
504+ self .obj .cache_active = self . original_cache_setting
508505 return False
509506
510507
0 commit comments