I just couldn't find anything explicit on the web about this, but it turns out to be really easy.
Libevent
Install libevent: http://www.monkey.org/~provos/libevent/
cd to libevent directory
Run: ./configure; sudo make; sudo make install;
Memcached
Install memcache: http://www.danga.com/memcached/download.bml
cd to memcached directory
Run: ./configure; sudo make; sudo make install;
I don't know if all the sudo's are required, but it failed do to permissions without it. I suspect it's just required on the 'make'.
The run memcache:
> memcache
It is started with defaults for the ip and port of 127.0.0.1:11211
In my environment.rb - I added
config.cache_store = :mem_cache_store, 'localhost', '127.0.0.1:11211'
Then - restarted my web app and started using Rails.cache.
To use it, in the controller do something like this:
@list_of_items = Rails.cache.fetch('list_of_items', :expires_in => 60*60 ) { Item.find(:all, :conditions => ['column = ?', @value]) }
The sudo should only be required on `make install` since that's what puts files in directories that you don't have permission to write to.
ReplyDelete