Skip to content

Instantly share code, notes, and snippets.

@mwpastore

mwpastore/sinatra.rb

Created Nov 25, 2015
Embed
What would you like to do?
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