Created
November 14, 2013 13:52
-
-
Save hoffm/7467113 to your computer and use it in GitHub Desktop.
Caching the response for a single page in Sinatra.
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
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