-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
klaus
committed
May 27, 2015
1 parent
906d017
commit 9e51138
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
|