Saturday, May 31, 2008

Introducing hibernate-memcached

Some of you may, or may not (care), know I am a huge fan of memcached. Its combination of simplicity, elegance and performance make it fantastic choice for any real caching solution.

I've recently begun work on implementing a bridge for using memcached as a second-level cache for hibernate. The project is hosted at googlecode right now, and the code is currently available in the googlecode hosted subversion repositories. In the future I'll probably move it over to github, but subversion is much more accessible to the public at large still.

Adding hibernate-memcached to your hibernate based application is as simple as adding hibernate-memcached.jar, memcached.jar, and spy.jar to your classpath. This can also be done using Maven.

Enabling the hibernate-memcached cache is simple as adding two properties to your hibernate config.

hibernate.memcached.servers=server1:11211 server2:11211

Property #1 tells Hibrnate to use the MemcachedCacheProvider. Property #2 tells the MemcachedClient in use what servers to use for the cache. It really is as simple as that.

There are many other configuration properties available to configure things like the default and per-region cache times, operation timeout, hash algorithm to use, and what key strategy to use.

The hibernate-memcached cache is working great for both individual entity caching and query caching. I currently have a lot of work to do around getting documentation up on the googlecode site. It is ready to play with and easy to setup, if anyone out there has the time to check out; please do! If you run into any questions or problems you can post them on the hibernate-memached google group, or open an issue at googlecode.

No comments: