Skip to content

Instantly share code, notes, and snippets.

@kinopyo
Created June 22, 2011 07:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save kinopyo/1039656 to your computer and use it in GitHub Desktop.
Save kinopyo/1039656 to your computer and use it in GitHub Desktop.
How to add memcached gem(Dalli) to Heroku with Sinatra
# Herodu Dev Center Doc:
# http://devcenter.heroku.com/articles/memcache
# Dalli gem heroku url:
# https://github.com/mperham/dalli
#######################
# Local Setup memcached
#######################
sudo port install memcached
# run the memcached daemon:
memcached -vv
#######################
#Using Memcache with Sinatra
#######################
# add gem to .gems (or Gemfile)
dalli
# install the gem
sudo gem install dalli
# require it first
require "dalli"
# add cache setting to yourapp.rb
# eg.cache for 10 min here. deault options is never expire
cache = Dalli::Client.new(nil, {:expires_in => 60*10})
set :cache, cache
# how to use
settings.cache.set('color', 'blue')
settings.cache.get('color') # => 'blue'
#######################
# Deploy to Heroku
#######################
heroku addons:add memcache
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment