diff --git a/oxrlib/loaders.py b/oxrlib/loaders.py index 2a600ed36a010e9e3e8dbd62e342f9c50efeaff5..3203d3196755912d55545357f2d8dc419bd00f2d 100644 --- a/oxrlib/loaders.py +++ b/oxrlib/loaders.py @@ -20,6 +20,9 @@ class FileCache(cache.CacheBase): def open(self, path): return self.CacheFile(path) + def is_cache(self): + return True + class OXRAPIRequest: DEFAULT_API_ROOT = 'https://openexchangerates.org/api/' @@ -30,6 +33,9 @@ class OXRAPIRequest: self.app_id = app_id self.open_url = open_func + def is_cache(self): + return False + def _get_response_encoding(self, response, default=None): try: content_type = response.getheader('Content-Type', 'application/json') @@ -69,9 +75,11 @@ class OXRAPIRequest: class LoaderChain: def __init__(self): self.loaders = [] + self.can_cache = False def add_loader(self, loader): self.loaders.append(loader) + self.can_cache = self.can_cache or loader.is_cache() def _wrap_load_method(orig_func): @functools.wraps(orig_func) @@ -93,3 +101,6 @@ class LoaderChain: @_wrap_load_method def historical(self, date, base): pass + + def should_cache(self): + return self.can_cache and self.used_loader and not self.used_loader.is_cache()