1. Skip to navigation
  2. Skip to content

The ELC Community Blog

A knowledge exchange on Ruby on Rails and Agile Development


Ehcache for JRuby / Rails

by Dylan Stamat on July 21, 2008

Spring, Hibernate, Linkedin.com... and the list goes on.
These are all projects that have chosen Ehcache as their caching solution... and with good reason !

Unlike Memcache, which most people in the Rails world are familiar with, Ehcache is a distributed and in-process caching solution, with asynchronous replication. Reads are extremely quick, as it all happens local and in-process... and writes are too... with all of the replication work happening asynchronously via RMI

Much more information...from the README:

== DESCRIPTION:

Ehcache is a simplified JRuby interface to Java's (JSR(107) compliant) Ehcache.
Simplified meaning that it should work out-of-the-box, but a lot of native
methods haven't been interfaced yet, as they weren't needed.  Configuration
occurs in config/ehcache.yml, and should support all the configuration
options available.

Some biased and non-biased Ehcache VS Memcache articles:
http://gregluck.com/blog/archives/2007/05/comparing_memca.html
http://feedblog.org/2007/05/21/unfair-benchmarks-of-ehcache-vs-memcached
http://blog.aristotlesdog.com/2008/05/01/memcached_vs_ehcache/
http://www.hugotroche.com/my_weblog/2008/06/ehcache-vs-memc.html

For more information on Ehcache, see:
http://ehcache.sourceforge.net/

Configuration, Code Samples and everything else, see:
http://ehcache.sourceforge.net/EhcacheUserGuide.html


== INSTALL:

jruby -S gem install ehcache


== BASIC USAGE:

manager = CacheManager.new
cache = manager.cache
cache.put("key", "value", {:ttl => 120})
cache.get("key")
manager.shutdown


== RAILS:

An EhcacheStore is available for use within Rails, so all the native
Rails caching methods are supported.  Make sure your config/environments/*,
are setup to support caching, eg: config.action_controller.perform_caching = true

1) From your RAILS_ROOT, run this command:
     - ehcache rails  ## just copies ehcache_store.rb into lib/ at the moment

2) In your environment.rb, specify:
     - config.cache_store = :ehcache_store

3) Cache stuff


== REQUIREMENTS:

Tested with JRuby 1.1.2 / Rails 2.1

Comments

milbup at 9:51 PM on September 20 2008

opqhhprujjcmyiwvofibtdzrhnqtnv

Add a comment


home | services | Ruby on Rails Development | code | blog | company