I have a QGIS project that makes heavy use of WFS for source layers. I tend to prefer this because I like to ensure that my map will stay current with changes to authoritive data sources (e.g. roads, administrative boundaries). My current region of interest is very small (a single town and small hinterland), but the WFS coming from a national government source is very large (many MBs of features that I'll never look at). QGIS seems good at limiting my requests, but on loading my project I find that it has to spend several minutes making WFS requests and re-downloading data that I'm positive is not going to change in the period that I'm working on my project.

I find this time waiting on these large WFS queries to complete is frustrating. Occasionally waiting on the response actually causes QGIS to crash, and I have to re-open QGIS and then it will start the downloads again from scratch.

Is there a way to set explicit client-side caching for WFS layers in the client (QGIS) to prevent a re-download? If I could tell QGIS to only perform a new query after a month (or whenever I deliberately clear or invalidate the cache), that would be ideal. I want this to work across sessions.

Existing similar questions and why they're not relevant:

I'm using QGIS 2.99 (master), which I gather is more or less QGIS 2.18.

Something I just observed: I found the reloading process this morning to be much faster than last night when I wrote a draft of this question, so it could be that I'm mistaken and that there already exists some kind of client-side cache or perhaps a mechanism for producing a diff and making a targeted query. However there was still one layer (landuse: with many thousands of complex features) that appeared to completely re-download. Is this then perhaps a matter of missing server-side cache headers for this particular service? This layer is from a different source than the rest of my layers. But is there still a way to declare a cache expiry in QGIS as the client, even if the server doesn't adequately set cache headers?

Indeed this question (Cached Featured in WFS - can I change default) suggests that QGIS does indeed default to caching WFS responses. (But the question asks whether there is a setting to override the use of a cache, which is related... and unanswered).

These questions (Is the QGIS cache directory automatically created? and How do I use a filter on an uncached WFS layer in QGIS?) tell me that QGIS definitely does caching. I'm only surprised because I keep seeing (some) of my own layers re-download after I restart.

  • If you want to keep features cached for a month, have you considered to save the layer locally into geopackage format?
    – user30184
    Apr 2 '17 at 8:48
  • I'll admit that that didn't actually occur to me, and that it is a good work-around, but I still think a way to set a property at the layer level would be superior, because saving the response to disk myself isn't readily automated. I'm not going to remember to re-request the layer. If it isn't possible, I think I might make a feature request. Apr 2 '17 at 9:06
  • I think that setting server side cache headers would mainly make sense with plain GetFeature requests because spatial and attribute filters tend to be more or less unique. Saving the layer as WFS-fetched-2017-04-02 would help you to remember when you took the data.
    – user30184
    Apr 2 '17 at 11:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.