4

I'm trying to find a method to cache one layer that its data is updated every 2 hours in the DB. From what I've found the best option is using Response Cache Headers timeout http://docs.geoserver.org/stable/en/user/webadmin/data/layers.html

What I've done is:

  1. enable direct integration with GeoServer WMS.
  2. add tiled=true parameter to WMS request
  3. replace http://GEOSERVER_URL/wms with http://GEOSERVER_URL/gwc/service/wms
  4. check "Response Cache Headers" with 7200 time specified as in http://docs.geoserver.org/stable/en/user/webadmin/data/layers.html

and when i look at the headers I see:

Cache-Control:max-age=7200, must-revalidate
Content-Disposition:inline; filename=geoserver-dispatch.image
Content-Type:image/png
Date:Sun, 04 May 2014 18:38:16 GMT
Expires:Sun, 04 May 2014 20:36:36 GMT
geowebcache-cache-result:HIT
geowebcache-crs:EPSG:900913
geowebcache-gridset:EPSG:900913
geowebcache-tile-bounds:12523442.712499999,2504688.5425000004,15028131.254999999,5009377.085000001
geowebcache-tile-index:[13, 9, 4]
geowebcache-tile-index:[13, 9, 4]
Last-Modified:Sun, 04 May 2014 07:06:05 GMT
Server:Apache-Coyote/1.1
Transfer-Encoding:chunked

I thought it worked but after 2 hours the layer didn't get updated! it's like that the layer is cached and frozen like forever. I think I'm missing something. any idea?

1

You might need to specifically ask GWC to truncate whatever has been generated so far.

I have some code to do this in Python, but basically you call something like this:

https://URL/geoserver/gwc/rest/layers/

with data like this:

{'seedRequest':{'minX':[],'minY':[],'maxX':[],'maxY':[],'gridSetId':gs,'zoomStart':00,'zoomStop':20,'format':imf,'type':'truncate','threadCount':2}}

(I do some other code to identify the gridsets and image formats, gs and imf, and then truncate all of them after I write data overnight.)

If you want the full code, take a look here: https://gist.github.com/alexgleith/844146bb24b4f22d856e

  • Thank you! I get it now. I'm thinking of scheduling truncate request every 15 min (since I'll set the headers timeout to 15 min) do you think it's gonna work? or it be expensive for the disk or something? – Shadin May 6 '14 at 15:55
  • Well, it removes the cache, so you wont have cached maps. It would be better to truncate the cached images only after the data changes. Otherwise, don't use GWC and read straight from GeoServer. – Alex Leith May 6 '14 at 23:05
  • okay it works now. turn out i mixed up the two methods! Thanks again. – Shadin May 8 '14 at 10:51

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.