I’ve been setting up some new mapping services (WMS) in GeoServer, with GeoWebCache allowing the map tiles to be cached for performance. For this to work, and for the WMS to use its cache of tiles, requires …
- the WMS request should include this on the KVP URL: &tiled=true
- the client should construct its tile requests so that they match the server tiles – this is not the place for elaboration, but essentially this means getting the origin and tile size correct
- the GeoServer must have “Enable direct integration with GeoServer WMS” switched on.
The setting in #3 is found under Tile Caching > Caching Defaults in the main GeoServer menu. Set it once, and forget it. Or so I thought.
How do we know if the WMS is using its cache? Insect the http requests in Fiddler (or similar) and check the headers of the responses.
If the WMS is using its cache you will see lines in the headers like this
along with various other geowebcache-… values
If it knows it has a cache, but something is wrong with the WMS requests (item #2 above), you might see headers like this:
geowebcache-miss-reason: request does not align to grid(s) 'OSGB27700'
And if the WMS is unaware it even has a cache of tiles at all, you will see nothing about geowebcache at all in the headers. And of course, poor WMS performance may give you a clue something is not working as you hoped.
Well I had set everything up lovely and my cache was working well, giving super fast performance of my Ordnance Survey mapping once the initial requests had populated the cache for an area.
But the very next day… performance was rubbish, and on inspecting the http headers, it turned out the WMS had forgotten about its cache.
In the GeoServer admin interface, the “Enable direct integration with GeoServer WMS” was now set to false. Grrr – I wondered how I could stupidly have switched that off again. Ah well, switch it on again and move on.
A few hours later… same again. This time I started suspecting colleagues, but there was no evidence, or motive, yet…
A couple more times, and I realised it was reverting after any re-start of GeoServer. I had been restarting every now and then, to make sure changed wrapper log settings etc. stuck, but it turned out this had been un-sticking my essential cache setting.
The solution turned out to be to edit the gwc-gs.xml file, found in the GeoServer data directory, and set this:
In my data dir, there was a gwc-gs.xml.tmp file, and I can only assume GeoServer had always failed to update the main XML file for some reason, used the .tmp version for the duration of the session, then reverted to the main one upon a re-start.
Now my cached WMS layers run nice and fast, and GeoServer doesn’t forget the setting.