Fork me on GitHub

12 Dec 2009

New Springcache Plugin Version

After saying it might take me a while I got stuck in and rewrote the Springcache plugin from scratch. The new version is up now. The plugin now requires Grails 1.2.0-M3 or greater as it's reliant on Spring 3.0.

The plugin allows you to declare caching and flushing behaviour on service methods (well, any Spring bean methods, but services are typical) using @Cacheable and @CacheFlush annotations. This is really useful for service methods that perform long-running or expensive tasks such as retrieving data from web services, network resources, etc. The plugin is less appropriate for service methods that retrieve data using GORM/Hibernate as you could just use the 2nd level cache, although there's nothing stopping you doing so if it makes sense in your domain.

The documentation and source code are in the usual places. Here's a quick summary of the changes and new features:

  • No longer depends on the (discontinued and non-Spring 3 compatible) spring-modules-cache library.
  • No more mapcache, the plugin now uses ehcache by default.
  • Only ehcache is supported directly but it's really easy to implement an adapter for other caching libraries if you need to.
  • Slightly simplified configuration. Some minor tweaks will be needed if you're upgrading from an earlier version of the plugin.
  • Bean names are now prefixed with "springcache" so they're much less likely to clash with other things in your Spring context.

There has been some interest in some new features such as a taglib for caching chunks of views which I may start looking at shortly.

5 comments:

Deepak Mittal said...

Hi Rob, thanks for the awesome plugin. Works beautifully in most cases; however, I have a specific case, where I don't want to flush the entire cache.

To explain -- my app stores data for multiple site; and I am caching the navigation for each site. Sites get created on the fly in the app. The problem that I am getting into is that when a new page is added to any of the site, I need to flush the "navigation" cache, which essentially flushes the cache for all sites.

Probably, what I need is that I should be able to created Caches on the fly -- with the name of the Cache being "Navigation" + Site.id. Is this something that is possible with the plugin?

Thanks again.
-Deepak

Rob said...

You're correct. Right now the flushable annotation is all or nothing. It's possible I could introduce some way to map service method parameters to cache 'regions' in a future version.

Depending on how you have ehcache configured the caches' contents will expire after a certain time anyway (unless they are set as eternal). It may be that the extra effort of flushing only a specific subset of cache contents doesn't actually result in that great a performance gain. It would be interesting to measure but anything like that is going to vary case-by-case depending on how the cache is used.

I'd be happy to look into implementing this kind of functionality, so feel free to raise a JIRA for an enhancement. Right now, however, the priority for the plugin's next version is the introduction of content caching.

michelcharles said...
This comment has been removed by the author.
meldaresearchusa said...

It has become vital that students seek assistance from genuine and experienced custom Pre Written Essays for Sale service providers if they intend to get the best pay for Nursing Papers for Sale service in the market.

shopify said...

Save on your online shopping with these vision direct promo code and offers