[mapserver-dev] Cache-control in WMS Requests

Bart van den Eijnden (OSGIS) bartvde at osgis.nl
Tue Mar 18 02:52:44 EDT 2008


Hey Paul,

why not leave this up to the webserver? That's more flexible IMHO. E.g.
using Apache's mod_headers.

Best regards,
Bart

--
Bart van den Eijnden
OSGIS, Open Source GIS
http://www.osgis.nl


--------- Oorspronkelijk bericht --------
Van: Paul Ramsey <pramsey at cleverelephant.ca>
Naar: mapserver-dev at lists.osgeo.org <mapserver-dev at lists.osgeo.org>
Onderwerp: [mapserver-dev] Cache-control in WMS Requests
Datum: 17/03/08 21:04

> All,
> 
> After doing a workshop with OpenLayers and Mapserver, one of the
> things I noticed was that browsers tend to beat on Mapserver more than
> they should, because they are not being told that they can cache the
> tiles they have retrieved.  As soon as the tiles move out-of-scope,
> they are gone, and moving back forces them to re-load.
> 
> For many applications, this behavior is way too hard on the server,
> particularly since the browser has a perfectly good local cache
> directory we could be taking advantage of.
> 
> I have (and it only took me 2 hours!) put together a five-line patch
> to mapwms.c that allows an optional &quot;http_max_age&quot; parameter in
the
> WEB metadata, and will set it.  I provide this as an example for
> discussion, not as a finished patch.  I need to add the HTTP 1.0
> equivalent before it could be applied.
> 
> The main question that came up as I spelunked around looking for the
> right place to insert this logic was &quot;where!?&quot;.  I ended up
settling
> on the WMS GetMap, because that's where clients like OpenLayers will
> tend to exercise it, but there are a number of places in the code
> generating stuff that could be flagged with cache-control information.
> 
> mode=legend, mode=map, getlegendgraphic, etc etc.
> 
> P.
> 
> ===================================================================
> --- mapwms.c	(revision 7459)
> +++ mapwms.c	(working copy)
> @@ -2196,8 +2196,15 @@
>      img = msDrawMap(map, MS_FALSE);
>    if (img == NULL)
>        return msWMSException(map, nVersion, NULL);
> -
> 
> +  /* Set the HTTP Cache-control headers if they are defined
> +     in the map object */
> +  const char *http_max_age;
> +  if( (http_max_age = msLookupHashTable(&amp;(map-&gt;web.metadata),
> &quot;http_max_age&quot;)) )
> +  {
> +    msIO_printf(&quot;Cache-control: max-age=%sn&quot;, http_max_age ,
10, 10);
> +  }
> +
>    msIO_printf(&quot;Content-type: %s%c%c&quot;,
>                MS_IMAGE_MIME_TYPE(map-&gt;outputformat), 10,10);
>    if (msSaveImage(map, img, NULL) != MS_SUCCESS)
> _______________________________________________
> mapserver-dev mailing list
> mapserver-dev at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/mapserver-dev
> 
> 





More information about the mapserver-dev mailing list