[mapserver-commits] r12431 - in trunk/mapserver/mapcache: include
src
svn at osgeo.org
svn at osgeo.org
Fri Aug 26 07:25:14 EDT 2011
Author: tbonfort
Date: 2011-08-26 04:25:14 -0700 (Fri, 26 Aug 2011)
New Revision: 12431
Modified:
trunk/mapserver/mapcache/include/geocache.h
trunk/mapserver/mapcache/src/core.c
trunk/mapserver/mapcache/src/mod_geocache.c
trunk/mapserver/mapcache/src/tileset.c
Log:
allow full wms operation by default
thomas.bonfort | 2011-08-15 18:25:17 +0200 (Mon, 15 Aug 2011)
Modified: trunk/mapserver/mapcache/include/geocache.h
===================================================================
--- trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:25:09 UTC (rev 12430)
+++ trunk/mapserver/mapcache/include/geocache.h 2011-08-26 11:25:14 UTC (rev 12431)
@@ -428,6 +428,8 @@
geocache_buffer *data;
int width, height;
double extent[4];
+ apr_time_t mtime; /**< last modification time */
+ int expires; /**< time in seconds after which the tile should be rechecked for validity */
};
struct geocache_feature_info {
Modified: trunk/mapserver/mapcache/src/core.c
===================================================================
--- trunk/mapserver/mapcache/src/core.c 2011-08-26 11:25:09 UTC (rev 12430)
+++ trunk/mapserver/mapcache/src/core.c 2011-08-26 11:25:14 UTC (rev 12431)
@@ -51,6 +51,15 @@
geocache_tileset_tile_get(ctx, tile);
if(GC_HAS_ERROR(ctx))
return NULL;
+
+ /* update the map modification time if it is older than the tile mtime */
+ if(tile->mtime>map->mtime) map->mtime = tile->mtime;
+
+ /* set the map expiration delay to the tile expiration delay,
+ * either if the map hasn't got an expiration delay yet
+ * or if the tile expiration is shorter than the map expiration
+ */
+ if(!map->expires || tile->expires<map->expires) map->expires = tile->expires;
}
geocache_image *getmapim = geocache_tileset_assemble_map_tiles(ctx,map->tileset,map->grid_link,
map->extent, map->width, map->height,
@@ -82,6 +91,9 @@
if(GC_HAS_ERROR(ctx)) return NULL;
geocache_image_merge(ctx,baseim,overlayim);
if(GC_HAS_ERROR(ctx)) return NULL;
+ if(overlaymap->mtime > basemap->mtime) basemap->mtime = overlaymap->mtime;
+ if(!basemap->expires || overlaymap->expires<basemap->expires) basemap->expires = overlaymap->expires;
+
}
basemap->data = basemap->tileset->format->write(ctx,baseim,basemap->tileset->format);
Modified: trunk/mapserver/mapcache/src/mod_geocache.c
===================================================================
--- trunk/mapserver/mapcache/src/mod_geocache.c 2011-08-26 11:25:09 UTC (rev 12430)
+++ trunk/mapserver/mapcache/src/mod_geocache.c 2011-08-26 11:25:14 UTC (rev 12431)
@@ -195,6 +195,33 @@
return OK;
}
+static int geocache_write_map(geocache_context_apache_request *ctx, geocache_map *map) {
+ int rc;
+ char *timestr;
+ request_rec *r = ctx->request;
+
+ if(map->expires) {
+ apr_time_t now = apr_time_now();
+ apr_time_t additional = apr_time_from_sec(map->expires);
+ apr_time_t expires = now + additional;
+ apr_table_set(r->headers_out, "Cache-Control",apr_psprintf(r->pool, "max-age=%d", map->expires));
+ timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
+ apr_rfc822_date(timestr, expires);
+ apr_table_setn(r->headers_out, "Expires", timestr);
+ }
+ if(map->mtime) {
+ ap_update_mtime(r, map->mtime);
+ if((rc = ap_meets_conditions(r)) != OK) {
+ return rc;
+ }
+ timestr = apr_palloc(r->pool, APR_RFC822_DATE_LEN);
+ apr_rfc822_date(timestr, map->mtime);
+ apr_table_setn(r->headers_out, "Last-Modified", timestr);
+ }
+ return geocache_write_image_buffer(ctx, map->data, map->tileset->format);
+}
+
+
static int geocache_write_tile(geocache_context_apache_request *ctx, geocache_tile *tile) {
int rc;
char *timestr;
@@ -343,7 +370,7 @@
if(GC_HAS_ERROR(global_ctx)) {
return report_error(apache_ctx);
}
- ret = geocache_write_image_buffer(apache_ctx,map->data, map->tileset->format);
+ ret = geocache_write_map(apache_ctx,map);
return ret;
} else if( request->type == GEOCACHE_REQUEST_GET_FEATUREINFO) {
geocache_request_get_feature_info *req_fi = (geocache_request_get_feature_info*)request;
Modified: trunk/mapserver/mapcache/src/tileset.c
===================================================================
--- trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:25:09 UTC (rev 12430)
+++ trunk/mapserver/mapcache/src/tileset.c 2011-08-26 11:25:14 UTC (rev 12431)
@@ -270,7 +270,7 @@
geocache_tileset* tileset = (geocache_tileset*)apr_pcalloc(ctx->pool, sizeof(geocache_tileset));
tileset->metasize_x = tileset->metasize_y = 1;
tileset->metabuffer = 0;
- tileset->expires = 0;
+ tileset->expires = 300; /*set a reasonable default to 5 mins */
tileset->auto_expire = 0;
tileset->metadata = apr_table_make(ctx->pool,3);
tileset->dimensions = NULL;
@@ -286,7 +286,11 @@
geocache_tile* geocache_tileset_tile_create(apr_pool_t *pool, geocache_tileset *tileset, geocache_grid_link *grid_link) {
geocache_tile *tile = (geocache_tile*)apr_pcalloc(pool, sizeof(geocache_tile));
tile->tileset = tileset;
- tile->expires = tileset->expires;
+ if(tileset->auto_expire) {
+ tile->expires = tileset->auto_expire;
+ } else {
+ tile->expires = tileset->expires;
+ }
tile->grid_link = grid_link;
if(tileset->dimensions) {
int i;
@@ -432,14 +436,13 @@
ctx->set_error(ctx, 500, "tileset %s: failed to re-get tile %d %d %d from cache after set", tile->tileset->name,tile->x,tile->y,tile->z);
}
}
- /* update the tile expiration time */
- if(tile->tileset->auto_expire && tile->mtime) {
- apr_time_t now = apr_time_now();
- apr_time_t expire_time = tile->mtime + apr_time_from_sec(tile->tileset->auto_expire);
- tile->expires = apr_time_sec(expire_time-now);
-
- }
}
+ /* update the tile expiration time */
+ if(tile->tileset->auto_expire && tile->mtime) {
+ apr_time_t now = apr_time_now();
+ apr_time_t expire_time = tile->mtime + apr_time_from_sec(tile->tileset->auto_expire);
+ tile->expires = apr_time_sec(expire_time-now);
+ }
}
void geocache_tileset_tile_delete(geocache_context *ctx, geocache_tile *tile) {
More information about the mapserver-commits
mailing list