local caching needs to take care of wms url

Issue #107 resolved
Reimar Bauer created an issue

Currently local caching does only take care about the URL parameters but not the URL itselfs.

One can fetch a lot of images and then change the URL to another one or even to some not existing.

Only get cabilities would enable to get different data.

So here we have two points to solve.

a) at the moment WMS Url becomes changed only get capabilties should be possible, all others should get inactive status

b) caching needs to take care of the Url used.

Comments (8)

  1. Reimar Bauer reporter

    This solves half of the issue and gives a hint what to do next

    diff --git a/mslib/msui/wms_control.py b/mslib/msui/wms_control.py
    index 18c4b4d..13e964f 100644
    --- a/mslib/msui/wms_control.py
    +++ b/mslib/msui/wms_control.py
    @@ -1228,19 +1228,23 @@ class WMSControlWidget(QtGui.QWidget, ui.Ui_WMSDockWidget):
                 if self.cachingEnabled():
                     kwargs["return_only_url"] = True
                     urlstr = self.wms.getmap(**kwargs)
    -                kwargs["return_only_url"] = False
    -                # Get an md5 digest of the URL string. The digest is used
    -                # as the filename.
    -                md5_filename = hashlib.md5(urlstr).hexdigest()
    -                md5_filename += ".png"
    -                logging.debug("checking cache for image file %s ...",
    -                              md5_filename)
    -                md5_filename = os.path.join(self.wms_cache, md5_filename)
    -                if os.path.exists(md5_filename):
    -                    logging.debug("  file exists, loading from cache.")
    -                    cache_hit = True
    +                if urlstr.startswith(self.cbWMS_URL.currentText()):
    +                    kwargs["return_only_url"] = False
    +                    # Get an md5 digest of the URL string. The digest is used
    +                    # as the filename.
    +                    md5_filename = hashlib.md5(urlstr).hexdigest()
    +                    md5_filename += ".png"
    +                    logging.debug("checking cache for image file %s ...",
    +                                  md5_filename)
    +                    md5_filename = os.path.join(self.wms_cache, md5_filename)
    +                    if os.path.exists(md5_filename):
    +                        logging.debug("  file exists, loading from cache.")
    +                        cache_hit = True
    +                    else:
    +                        logging.debug("  file does not exist, retrieving from WMS server.")
                     else:
    -                    logging.debug("  file does not exist, retrieving from WMS server.")
    +                    logging.debug("  Url does not match, use get capabilities first.")
    +                    raise RuntimeError("Url does not match, use get capabilities first.")
    
                 if not cache_hit:
    
  2. Log in to comment