Skip to content

Conversation

nuclearsandwich
Copy link
Member

This commit uses Sinatra's cache_control helper in a before filter to add caching via Heroku's Varnish. It will only work on the Bamboo stack but that's likely what this app will use for the immediate future.

This probably won't do much for load times but it will certainly assist with server responsiveness druing workshops. What's more, there's no reason not to cache since the caches are cleared on every deploy and between deploys the content is static.

There is a working mirror of the installfest app with this commit applied at http://sammich-installfest.heroku.com.

The caching can be observed using Faraday with the following:

require "faraday"
print_method = begin
                 require "awesome_print"
                 :ap
               rescue LoadError
                 require "pp"
                 :pp
               end

url = "http://installfest.railsbridge.org/installfest/installfest"
cached_url = "http://sammich-installfest.heroku.com/installfest/installfest"

installfest = Faraday::Connection.new url
cached_installfest = Faraday::Connection.new cached_url

puts "# Hitting #{url}, observe no Cache-Control header."
send(print_method, installfest.get.headers)

puts "\n", "# Hitting #{cached_url}, observe the public Cache-Control header."
send(print_method, cached_installfest.get.headers)

which yields

# Hitting http://installfest.railsbridge.org/installfest/installfest
# observe no Cache-Control header.
{
               "server" => "nginx/0.7.67",
                 "date" => "Tue, 27 Dec 2011 18:36:39 GMT",
         "content-type" => "text/html;charset=utf-8",
    "transfer-encoding" => "chunked",
           "connection" => "close",
      "x-frame-options" => "sameorigin",
     "x-xss-protection" => "1; mode=block",
            "x-varnish" => "1237521881",
                  "age" => "0",
                  "via" => "1.1 varnish"
}

# Hitting http://sammich-installfest.heroku.com/installfest/installfest
# observe the public Cache-Control header.
{
               "server" => "nginx/0.7.67",
                 "date" => "Tue, 27 Dec 2011 18:36:40 GMT",
         "content-type" => "text/html;charset=utf-8",
    "transfer-encoding" => "chunked",
           "connection" => "close",
      "x-frame-options" => "sameorigin",
     "x-xss-protection" => "1; mode=block",
        "cache-control" => "public, max-age=3600",
              "expires" => "Tue, 27 Dec 2011 19:32:55 GMT",
            "x-varnish" => "526466651 526390325",
                  "age" => "225",
                  "via" => "1.1 varnish"
}

alexch added a commit that referenced this pull request Jan 5, 2012
Add before filter to cache pages for an hour.
@alexch alexch merged commit 77eecb5 into railsbridge:master Jan 5, 2012
alexch pushed a commit to alexch/railsbridge-docs that referenced this pull request Jan 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants