« The new ehcache server | Main | Spnego 1.1 (Kerberos between browsers and Java App servers) released »

July 29, 2008

Ehcache for JRuby/JRuby on Rails

I am pleased to announce that Dylan Stamat has just released Ehcache for JRuby.JRuby on Rails.

Quick Start

Following is a quickstart reproduced from his blog. HIs company is migrating from Ruby to JRuby and wanted to try in-process caching.

== 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.actioncontroller.performcaching = true

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

2) In your environment.rb, specify: - config.cachestore = :ehcachestore

3) Cache stuff

Q and A - Greg Luck and Dylan Stamat

Q: What are the reasons you are migrating from Ruby MRI (C Ruby) to JRuby?

A: There were quite a few reasons we decided to adopt JRuby, and probably like most adopters, the deployment and applications options that became available were extremely appealing. Our current stack is deployed on MRI, and runs pretty heavy. In some crude testing of our application deployed to Glassfish, we had a significantly smaller footprint... and an easier to maintain one at that.

Q: Ok, so why the move from memcached to ehcache? You can still use memcached from JRuby and that is the default cache most people use.

A: In the MRI world, we use memcached, which is a Ruby interface to the libmemcached C client. It is one of the only Ruby libraries that currently supports consistent hashing, which is a requirement for our production environment. When preparing for JRuby, we had a different set of options. One was writing our own hooks into libmemcached via JNA, JRuby FFI, etc. The other was to look for another cache solution in Java, and Ehcache was definitely on top of the list. We happen to have a very read heavy application, and are not bound to using a distributed cache... so Ehcache seemed like a very logical fit.

Q: How is JRuby packaged and what plans are there to keep the JRuby interface in sync with ehcache?

A: Anyone running JRuby, and needing a caching solution, should look at the Ehcache JRuby gem. It's a very simple interface to what Ehcache has to offer (which is a lot), and I would love to see it become an up-to-date mirror of the Ehcache project at some point. (Greg: Ehcache 1.5.0 got released just as Dylan was finalising the JRuby adapter)

Q; What are the production benefits of JRuby/Ehcache over Ruby MRI/Memcached?

A: I'm running the gem on a very low volume, internal system, and it definitely works like a charm... and am pretty confident that our current application is testing the limits of JRuby / MRI compatibility ;) We currently have two bottlenecks on our JRuby initiative, one is getting our entire test suite JRuby compatible, which is proving to be a bit more involved than we thought. The other one was tracking down some intermittent marshalling issues we're running into when using the Ehcache JRuby gem which we have just resolved today (Greg: 28 July 2008).

I'll definitely try and get some sign off on using it (the intended production web sites) in the future so you can add them to your "who uses Ehcache" list in the future. (Greg: Suffice to say that the JRuby/Ehcache/Glassfish solution is intended to run some large public facing websites).

Project Details

Visit the project:

Code: http://github.com/dylanz/ehcache/tree/master Google Group: http://groups.google.com/group/ehcache-jruby Bug Tracker: http://dylanz.lighthouseapp.com/projects/14518-ehcache-jruby/overview

And, a ticket system for the project here: http://dylanz.lighthouseapp.com/projects/14518-ehcache-jruby/overview Will definitely get a ticket in there for updating it to use ehcache-1.5.0 ;)

Posted by gluck at July 29, 2008 04:00 PM

Comments