Created
November 25, 2015 22:46
-
-
Save mwpastore/dc8f39cdadac4a6e32ad to your computer and use it in GitHub Desktop.
Sinatra with caching example
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
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