JCache API comes with several built in interceptors for CDI making its usage decoupled from the cache API itself and more user friendly.
Let’s have a look to this API.
CacheResult: the method execution killer
Probable one of the most common use cache is to avoid to pay the cost of a method each time you call it.
Reasons can be as different as:
- Computation done by the method is expensive
- The method contacts a remote service and you want to cut off the implied latency
- The method accesses a rate limited resource
In this cache @CacheResult brings a nice and easy to setup solution. Simply decorating the method with @CacheResult you will avoid the actual method invocation after the first call and while it is cached.
Here a sample using a service simulating a slow method:
On friday I did with Jean-Louis Monteiro the Lorraine JUG. I presented Apache JCS which is a nice Java Caching solution implementing now JCache specification.
Slides are available here: http://rmannibucau.github.io/2015/LorraineJUG/#/.
And few code samples/examples can be found here (this is a maven project you can open in your IDE): https://github.com/rmannibucau/rmannibucau.github.com/tree/master/2015/LorraineJUG/demo.
Don’t hesitate to get in touch the Apache JCS community if you want more information (use Apache Commons mailing list – email@example.com – and just specify [JCS] in the subject), we’ll be very happy to help you!
Extra module of commons-jcs provides some interesting basic features to use with JCache.
This post is just a quick overview of them.
Apache JCS project now has a new “openjpa” module. This one allows to use JCache (whatever implementation it is) as OpenJPA L2 cache.
JCache is the standard API for cache libraries. One common need is to
link the cache with another data source like a database (RDBMS or
Of course JCache handles both access types: reader and writer.
This post is about readers.
JCache is out since some months and we already have some implementations popping out (Hazelcast implemented the main part, Infinispan passes all TCKs, commons-jcs passes standalone TCKs – CDI implementation in progress, Spring just integrated it etc…).
This article is just here to present the basic API but some more will come with the features which can make it interesting compared to more simple APIs (like a Map).