JBossCache Plugin

  • Tags : performance, utility
  • Latest : 0.1.9
  • Last Updated: 18 May 2009
  • Grails version : 1.1.1 > *
  • Authors : Mingfai Ma
0 vote
Dependency :
compile ":jbosscache:0.1.9"

Documentation

Summary

Description

JBossCache is an enterprise-grade replicated cache. This plugin allows easy installation of JBossCache library, @JBossCache annotation to inject cache, a JbosscacheService for Cache creation, and enhanced Cache with additional Groovy-style API

Feature

  • provide all JBossCache and depended libraries
  • provide a JBosscacheService for creating cache instance
    • it creates a DefaultCacheFactory upon lazy-init
    • it call CacheEnhancer to add some Grails style API to Cache (see the next bullet)
  • Extend the JBossCache Cache API with some Groovy style APIs
    • by default, JBossCache provides API argument as FQN or String
    • in Groovy, we use '[1,2,3]' to define an ArrayList easily. The JBossCache Cache interface is enhanced with a set of methods that take a List as an argument to determine a node
    • refer to Cache.java for all additional interface
    • <0.1.4> @JBossCache annotation to inject a Cache instance for any Spring managed bean
  • Remarks: from <0.1.4> demo controller is removed and sample configuration will not copied to your project folder.
    • <0.1.6> added a org.grails.plugins.jbosscache.JBossCache class as a convenient constructor/builder for a cache

Demonstration

  1. <0.1.4> Demo controller is removed and the demonstration requires Grails Console Plugin
  2. pre-requisite: JDK and Grails are properly setup
  3. Create the first project named 'node1', , under any directory:
    grails create-app node1 #create the Grails project
    cd node1
    grails install-plugin jbosscache #install this plugin
    grails install-plugin console #install the console plugin for demo purpose
    grails run-app #start the node at the default port 8080
    
  4. create the 2nd node named 'node2', but start it at port 8081
    grails create-app node2 #create the Grails project
    cd node1
    grails install-plugin jbosscache #install this plugin
    grails install-plugin console #install the console plugin for demo purpose
    grails -Dserver.port=8081 run-app #start the node at the port 8081
    
  5. Access the console
  6. Play with a cache
    1. At node1
      def cacheService = context.getBean("jbosscacheService")
      cache = cacheService.getCache("demo") //create the cache and store in a 'cache' variable
      //press Execute button
      
    2. At node2
      def cacheService = context.getBean("jbosscacheService")
      cache = cacheService.getCache("demo") //create the cache and store in a 'cache' variable
      //press Execute button
      
    3. At node1
      cache.put('/','foo','bar')
      //press Execute button
      
    4. At node2
      cache.get('/','foo')
      //press Execute button
      

Cache usage

API

  • This plugin is for helping you to use JBossCache. You have to know about JBossCache in order to use it. Check the JBossCache documentation page. For application developers, you will want to check the API docs to know about the Cache interface.

@JBossCache annotation

  • <0.1.4> You could use an @JBossCache annotation to inject a cache to a field for your Spring-managed bean
  • example
    import org.grails.plugins.jbosscache.annotation.JBossCache
    
    class Bar{
     @JBossCache(name="foobar") bar
    }
    
  • See test case at svn
  • The @JBossCache annotation injected cache will have a getDefaultNode() method, and you could utilize the put(key,value) and get(key) interface. The default node is the 'name' in the annotation or the full class name in Fqn. e.g. foo.bar.FoobarService.class will be the Fqn of "/foo/bar/FoobarService"
  • In case you want to use JBossCache but will not use the annotation, you may disable it with 'plugins.jbosscache.annotation.disable=true' with system property or in Config.groovy. The annotation is enabled by default, but in future version, it is considering to require explicit enabling by default.
    • remarks, the injection is done with a Spring BeanPostProcessor. If enabled, every field in every bean initialized in Spring will be scanned for the @JBossCache annotation. The property/configuration could avoid this very small resource usage.

JBossCache class

  • From <0.1.6>, other than using the original JBossCache API or the jbosscacheService, there is an additional way to create a cache instance with org.grails.plugins.jbosscache.JBossCache.
    • to create a local cache
      def cache = new JBossCache()
      • by default, it uses jbosscache/sample/local.xml
      • CacheEnhancer will be called, and the cache instance will be added with defaultNode
    • to use another configuration, use: new JBossCache(config:'replicate-all')
    • Check the source for details

Version and Compatiability

  • Last tested with Grails 1.1 RC 1 / Groovy 1.6.0
  • JDK 5+
  • Plugin 0.1.1+ - JBossCache Core Edition 3.0.2 GA
see the CHANGES.txt for update

Reference Links

Roadmap

  • The next version will configure JBossCache as Hibernate 2nd level cache
  • Provide a interactive cluster demo together with Cometd and GridGain Plugin
  • check the TODO list in svn trunk

Contact and Author

  • Please send any question to the grails user mail list. For JBossCache issues, please go to JBossCache's forum. There is no issue tracking yet.
Author: Mingfai Ma (mingfai.ma at gmail dot com)