Created
April 19, 2013 10:49
-
-
Save letronje/5419621 to your computer and use it in GitHub Desktop.
varnish
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
Routes: | |
match '/test/:id' => 'dummy#test' | |
match '/user/:id' => 'dummy#user' | |
------------------------------------- | |
Controller: | |
def test | |
Rails.logger.ap "*"*100 | |
response.headers['Cache-Control'] = "public, max-age=86400" | |
render :layout => false | |
end | |
def user | |
response.headers['Cache-Control'] = "public, max-age=86400" | |
x = { | |
"manoj" => "Manoj Mathai", | |
"manish" => "Manish Mathai", | |
"yadav" => "Nilesh Yadav" | |
} | |
render :text => x[params[:id]] | |
end | |
-------------------------------------- | |
View: | |
<h1>Welcome</h1> | |
<esi:include src="/user/<%= params[:id] %>" /> | |
<h1> | |
Time is <%= Time.now %> | |
</h1> | |
-------------------------------------- | |
VCL: | |
sub vcl_deliver { | |
if (obj.hits > 0) { | |
set resp.http.X-Cache = "HIT"; | |
set resp.http.X-Cache-Hits = obj.hits; | |
} else { | |
set resp.http.X-Cache = "MISS"; | |
} | |
} | |
sub vcl_recv { | |
#unset req.http.Cache-Control; | |
if (req.request == "PURGE") { | |
return (lookup); | |
} | |
} | |
sub vcl_hit { | |
if (req.request == "PURGE") { | |
purge; | |
error 200 "Purged."; | |
} | |
} | |
sub vcl_miss { | |
if (req.request == "PURGE") { | |
purge; | |
error 200 "Purged."; | |
} | |
} | |
sub vcl_fetch { | |
remove beresp.http.Cache-Control; | |
if (req.url ~ "/test/") { | |
set beresp.do_esi = true; /* Do ESI processing */ | |
} | |
} | |
sub vcl_hash { | |
hash_data(req.url); | |
if (req.http.host) { | |
hash_data(req.http.host); | |
} else { | |
hash_data(server.ip); | |
} | |
if(req.url ~ "/user/"){ | |
hash_data(req.http.cookie); | |
} | |
return (hash); | |
} | |
sub vcl_recv { | |
if (req.http.Authorization) { | |
return (pass); | |
} | |
return (lookup); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment