Memcached Server with Rails

To install memcached server on linux/fedora box
yum install memcached

Find help for memcached commands and option
memcached -help

Start memcached server(11211 is default port Number for memcached server)
memcached -m 500 -l -p 11211 -vv
( this is my local ip address you can cahnge that)

Stop the Memcached server
ps -ef|grep memcached

start memcached server with
memcached -m 500 -l -p 11211 -vv

How to install on Windows server:
1.  Downloaded this Win32 port of memcached by Kenneth Dalgleish.(download from following url)
2. Extracted the files to C:\Program Files\memcached
3. Opened a command prompt in the folder and installed memcached as a service using memcached -d install
4. Started the service using net start “memcached Server”

How to use memcache in Rails app?
Open  /config/environments/development.rb for development mode,
production.rb for production mode.
paste following line into file.
config.cache_store = :mem_cache_store, ‘’, ‘’ , { :namespace => ‘dev’ }
( this is my local ip address you can cahnge or point out to any server where memcached server is running)
Restart mongrel server. you are ready to use memcached server

How to use in Rails
@user= User.find(1)—–OLD Code

New Code With Caching:
@user = cache([‘User’,1],:expires_in => 30.minutes) do

Add a Comment

Your email address will not be published. Required fields are marked *