Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
klaus committed May 27, 2015
1 parent 906d017 commit 9e51138
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 0 deletions.
6 changes: 6 additions & 0 deletions openstreetmap/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@


Vcl script for openstreetmap.

The purpose is to cache all tiles for a long time, so openstreetmap servers doesn't get overloaded

78 changes: 78 additions & 0 deletions openstreetmap/openstreetmap4.vcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
vcl 4.0;

backend default {
.host = "127.0.0.1";
.port = "80";
}


backend a_tile {
.host = "a.tile.openstreetmap.org";
.port = "80";
}

backend b_tile {
.host = "b.tile.openstreetmap.org";
.port = "80";
}

backend c_tile {
.host = "c.tile.openstreetmap.org";
.port = "80";
}

sub vcl_recv {

if (req.http.host ~ "^a.tile") {
set req.backend_hint = a_tile;
} else if (req.http.host ~ "^b.tile") {
set req.backend_hint = b_tile;
} else if (req.http.host ~ "^c.tile") {
set req.backend_hint = c_tile;
} else if (req.http.host ~ "^a.map") {
set req.backend_hint = a_tile;
} else if (req.http.host ~ "^b.map") {
set req.backend_hint = b_tile;
} else if (req.http.host ~ "^c.map") {
set req.backend_hint = c_tile;
}

unset req.http.cookie;

// Cache everything
if (req.method == "GET") {
return (hash);
}


}

sub vcl_backend_response {

// Cache tiles for 3 weeks
set beresp.ttl = 3w;

// Remove all cookies
unset beresp.http.set-cookie;
unset beresp.http.cookie;

}

sub vcl_deliver {


if (obj.hits > 0) {
set resp.http.X-Cache_v = "HIT";
} else {
set resp.http.X-Cache_v = "MISS";
}
}

sub vcl_hash {

// Cache using only url as a hash.
// This means if a.tile/1/1/1/tile.png is access, b.tile/1/1/1/tile.png will also be fetch from cache
hash_data(req.url);
return (lookup);
}

0 comments on commit 9e51138

Please sign in to comment.