response.headers['Cache-Control'] = 'max-age=1000000'
(params[:n].to_i * 4).to_s
ruby sinatra-add.rb -e productionand you're done.
There are, of course, many other fiddly bits to configure Rack::Cache with, like
use Rack::Cache, :entitystore => 'file:/tmp/'if you don't want to keep it all in a hash in memory, and
:verbose => falseif you don't want that in your logs, but that's basically it.
It's pretty amazing: that's a real live web service, with HTTP caching, in 7 gentle lines. (I don't count the closing brace, nor the sleep 1, which is purely for effect.)
Anyone know an easier way in any other language? Either in number of lines, or in directness of code?
Also, how bad would it be to authbind that to port 80, and just let it go open to the world?
Update: It's interesting to me for the same reason PHP is interesting, both as a social commentary on the bits of plumbing we've agreed upon as useful, and as an aid to wrapping an HTTP interface around some Ada code with its own homegrown database.