How to:

  1. You need CDI (and Infinispan if you re-use the code without altering it)
  2. Grab the code from the Gist and put it into your project
  3. Annotate the methods you want to use the caching
  4. Enable the caching interceptor in your beans.xml
    <beans xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://jboss.org/schema/cdi/beans_1_0.xsd">
        <interceptors>
            <class>...CachingInterceptor</class>
        </interceptors>
    </beans>
  5. Build yourself a clear operation to manually evict the cache, you'll need it.

Gist