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