added last-modified header to tiler
This commit is contained in:
@@ -38,6 +38,7 @@ function GenericCache (cache_policy, cache_validator) {
|
||||
cache_validator: cache_validator,
|
||||
cache_hits: 0,
|
||||
cache_misses: 0,
|
||||
cache_not_modified: 0,
|
||||
current_items: 0,
|
||||
cache_invalidated: 0,
|
||||
max_items: 0
|
||||
@@ -61,17 +62,29 @@ function GenericCache (cache_policy, cache_validator) {
|
||||
if(tile) {
|
||||
// validate the cache
|
||||
me.cache_validator.getTimestamp(req.params.dbname, req.params.table, function(err, t) {
|
||||
if(t != null && tile.timestamp < t) {
|
||||
if(t !== null && tile.timestamp < t) {
|
||||
me.cache_misses++;
|
||||
me.cache_invalidated++;
|
||||
callback(null);
|
||||
} else {
|
||||
// stats
|
||||
me.cache_hits++;
|
||||
var timestamp = new Date().getTime();
|
||||
var delta = timestamp - req.windshaft_start;
|
||||
tile.cache_time = delta/1000.0;
|
||||
tile.hits++;
|
||||
res.header('X-Cache-hit', 'true');
|
||||
res.header('Last-Modified', new Date(tile.timestamp*1000).toGMTString());
|
||||
// check 304
|
||||
var modified_since = req.header('if-modified-since');
|
||||
if (modified_since) {
|
||||
modified_since = Date.parse(modified_since);
|
||||
if(modified_since && modified_since <= timestamp*1000) {
|
||||
me.cache_not_modified++;
|
||||
res.send(304);
|
||||
return;
|
||||
}
|
||||
}
|
||||
res.send(tile.tile, tile.headers, 200);
|
||||
}
|
||||
});
|
||||
@@ -87,7 +100,7 @@ function GenericCache (cache_policy, cache_validator) {
|
||||
me.cache.put(cache_key(req), {
|
||||
tile: tile,
|
||||
headers: headers,
|
||||
timestamp: timestamp,
|
||||
timestamp: timestamp/1000.0,
|
||||
render_time: delta/1000.0,
|
||||
hits: 0});
|
||||
update_items(me.cache.size || 0);
|
||||
@@ -95,7 +108,6 @@ function GenericCache (cache_policy, cache_validator) {
|
||||
}
|
||||
|
||||
me.afterStateChange = function(req, data, callback) {
|
||||
console.log("invalidating", req.params.dbname,", ", req.params.table);
|
||||
me.cache_validator.setTimestamp(req.params.dbname, req.params.table, new Date().getTime()/1000.0, function(err, t) {
|
||||
callback(err, data);
|
||||
});
|
||||
@@ -123,7 +135,6 @@ function GenericCache (cache_policy, cache_validator) {
|
||||
});
|
||||
}
|
||||
});
|
||||
console.log(sort_by);
|
||||
sort_by = sort_by || 'hits';
|
||||
tile_info.sort(function(a, b) {
|
||||
return b[sort_by] - a[sort_by];
|
||||
@@ -131,6 +142,8 @@ function GenericCache (cache_policy, cache_validator) {
|
||||
return {
|
||||
cache_hits: me.cache_hits,
|
||||
cache_misses: me.cache_misses,
|
||||
cache_invalidated: me.cache_invalidated,
|
||||
cache_not_modified: me.cache_not_modified,
|
||||
current_items: me.current_items,
|
||||
max_items: me.max_items,
|
||||
memory: mem,
|
||||
|
||||
Reference in New Issue
Block a user