Skip to content

Instantly share code, notes, and snippets.

@mwpastore
Created November 25, 2015 22:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwpastore/dc8f39cdadac4a6e32ad to your computer and use it in GitHub Desktop.
Save mwpastore/dc8f39cdadac4a6e32ad to your computer and use it in GitHub Desktop.
Sinatra with caching example
require 'sinatra/base'
require 'concurrent'
class App < Sinatra::Application # or ::Base for fewer features
configure do
set :cache, Concurrent::Hash.new(0)
end
get '/?:word?' do
word = params[:word]
count = settings.cache[word] += 1
"`#{word}` was called #{count} times"
end
run! if app_file == $0
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment