[mapserver-commits] r12139 - in trunk/mapserver/mapcache: . include src

svn at osgeo.org svn at osgeo.org
Fri Aug 26 07:01:04 EDT 2011


Author: tbonfort
Date: 2011-08-26 04:01:04 -0700 (Fri, 26 Aug 2011)
New Revision: 12139

Modified:
   trunk/mapserver/mapcache/geocache.xml
   trunk/mapserver/mapcache/include/geocache.h
   trunk/mapserver/mapcache/src/configuration.c
   trunk/mapserver/mapcache/src/image.c
   trunk/mapserver/mapcache/src/mod_geocache.c
   trunk/mapserver/mapcache/src/tileset.c
Log:
add documentation, split imageio into png and jpeg files
thomas.bonfort | 2010-10-25 10:45:47 +0200 (Mon, 25 Oct 2010)

Modified: trunk/mapserver/mapcache/geocache.xml
===================================================================
--- trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:00:58 UTC (rev 12138)
+++ trunk/mapserver/mapcache/geocache.xml	2011-08-26 11:01:04 UTC (rev 12139)
@@ -39,6 +39,7 @@
         <metatile>5 5</metatile>
         <metabuffer>30</metabuffer>
         <format>JPG</format>
+        <expires>3600</expires>
     </tileset>
     <tileset name="test2">
         <source>nexrad</source>

Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:00:58 UTC (rev 12138)
+++ trunk/mapserver/mapcache/include/geocache.h	2011-08-26 11:01:04 UTC (rev 12139)
@@ -65,6 +65,7 @@
    geocache_buffer *data;
    void *lock;
    apr_time_t mtime;
+   int expires;
 } geocache_tile;
 
 typedef struct {
@@ -146,6 +147,7 @@
    double *resolutions;
    int metasize_x, metasize_y;
    int metabuffer;
+   int expires;
    geocache_image_format_type format;
    geocache_cache *cache;
    geocache_source *source;

Modified: trunk/mapserver/mapcache/src/configuration.c
===================================================================
--- trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:00:58 UTC (rev 12138)
+++ trunk/mapserver/mapcache/src/configuration.c	2011-08-26 11:01:04 UTC (rev 12139)
@@ -252,17 +252,25 @@
          tileset->metasize_x = values[0];
          tileset->metasize_y = values[1];
          xmlFree(value);
+      } else if(!xmlStrcmp(cur_node->name, BAD_CAST "expires")) {
+         value = (char*)xmlNodeGetContent(cur_node);
+         char *endptr;
+         tileset->expires = (int)strtol(value,&endptr,10);
+         if(*endptr != 0)
+            return apr_psprintf(pool,"failed to parse expires %s."
+                  "(expecting an  integer, "
+                  "eg <expires>3600</expires>",
+                  value);     
+         xmlFree(value);
       } else if(!xmlStrcmp(cur_node->name, BAD_CAST "metabuffer")) {
          value = (char*)xmlNodeGetContent(cur_node);
          char *endptr;
          tileset->metabuffer = (int)strtol(value,&endptr,10);
          if(*endptr != 0)
             return apr_psprintf(pool,"failed to parse metabuffer %s."
-                  "(expecting an integer integer, "
+                  "(expecting an  integer, "
                   "eg <metabuffer>1</metabuffer>",
                   value);     
-
-
          xmlFree(value);
       } else if(!xmlStrcmp(cur_node->name, BAD_CAST "format")) {
          value = (char*)xmlNodeGetContent(cur_node);

Modified: trunk/mapserver/mapcache/src/image.c
===================================================================
--- trunk/mapserver/mapcache/src/image.c	2011-08-26 11:00:58 UTC (rev 12138)
+++ trunk/mapserver/mapcache/src/image.c	2011-08-26 11:01:04 UTC (rev 12139)
@@ -65,12 +65,16 @@
    int i;
    geocache_tile *tile = apr_pcalloc(r->pool,sizeof(geocache_tile));
    tile->mtime = tiles[0]->mtime;
+   tile->expires = tiles[0]->expires;
    base = geocache_imageio_decode(r, tiles[0]->data);
    if(!base) return NULL;
    for(i=1; i<ntiles; i++) {
       overlay = geocache_imageio_decode(r, tiles[i]->data);
       if(tile->mtime < tiles[i]->mtime)
          tile->mtime = tiles[i]->mtime;
+      if(tiles[i]->expires && ((tile->expires < tiles[i]->expires) || !tile->expires)) {
+         tile->expires = tiles[i]->expires;
+      }
       if(!overlay) return NULL;
       _geocache_image_merge(r, base, overlay);
    }

Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:00:58 UTC (rev 12138)
+++ trunk/mapserver/mapcache/src/mod_geocache.c	2011-08-26 11:01:04 UTC (rev 12139)
@@ -41,6 +41,16 @@
    if((rc = ap_meets_conditions(r)) != OK) {
       return rc;
    }
+   if(tile->expires) {
+      apr_time_t now = apr_time_now();
+      apr_time_t additional = apr_time_from_sec(tile->expires);
+      apr_time_t expires = now + additional;
+      apr_table_mergen(r->headers_out, "Cache-Control",apr_psprintf(r->pool, "max-age=%d", tile->expires));
+      char *timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
+      apr_rfc822_date(timestr, expires);
+      apr_table_setn(r->headers_out, "Expires", timestr);
+
+   }
    ap_set_last_modified(r);
    ap_set_content_length(r,tile->data->size);
    if(tile->tileset->source->image_format == GEOCACHE_IMAGE_FORMAT_PNG) 

Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c	2011-08-26 11:00:58 UTC (rev 12138)
+++ trunk/mapserver/mapcache/src/tileset.c	2011-08-26 11:01:04 UTC (rev 12139)
@@ -161,6 +161,7 @@
    geocache_tileset* tileset = (geocache_tileset*)apr_pcalloc(pool, sizeof(geocache_tileset));
    tileset->metasize_x = tileset->metasize_y = 1;
    tileset->metabuffer = 0;
+   tileset->expires = 0;
    tileset->tile_sx = tileset->tile_sy = 256;
    tileset->extent[0]=tileset->extent[1]=tileset->extent[2]=tileset->extent[3]=0;
    tileset->forwarded_params = apr_table_make(pool,1);
@@ -174,6 +175,7 @@
 geocache_tile* geocache_tileset_tile_create(geocache_tileset *tileset, apr_pool_t *pool) {
    geocache_tile *tile = (geocache_tile*)apr_pcalloc(pool, sizeof(geocache_tile));
    tile->tileset = tileset;
+   tile->expires = tileset->expires;
    tile->sx = tileset->tile_sx;
    tile->sy = tileset->tile_sy;
    return tile;



More information about the mapserver-commits mailing list