Skip to content

Instantly share code, notes, and snippets.

@hoffm
Created November 14, 2013 13:52
Show Gist options
  • Save hoffm/7467113 to your computer and use it in GitHub Desktop.
Save hoffm/7467113 to your computer and use it in GitHub Desktop.
Caching the response for a single page in Sinatra.
get '/' do
if !File.exist?('cache') || (File.mtime('cache') < (Time.now - 1800))
puts "**********CACHE MISS**********"
data = erb(:index)
File.open('cache',"w"){ |f| f << data }
else
puts "**********CACHE HIT**********"
end
send_file 'cache', :type => 'html'
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment