Skip to content

Instantly share code, notes, and snippets.

@rtomayko
Created April 16, 2009 21:16
Show Gist options
  • Save rtomayko/96663 to your computer and use it in GitHub Desktop.
Save rtomayko/96663 to your computer and use it in GitHub Desktop.
class CachePolicy < Sinatra::Base
# always forward the request downstream immediately (before processing routes)
before { forward }
# anything with a cache breaking timestamp gets an insanely long max-age
get '/public/*' do
pass unless request.query_string =~ /^\d+$/
response['Cache-Control'] = 'public, max-age=1000000000'
end
# PNGs get a 5 minute ttl
get '/public/*.png' do
response['Cache-Control'] = 'public, max-age=300'
end
# everything else is private
get '/*' do
response['Cache-Control'] = 'private'
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment