Showing posts with label cache. Show all posts
Showing posts with label cache. Show all posts

Sunday, May 19, 2013

Using Spring-Cache-Guava

 Spring-Cache-Guava, uses the Maven build system. Building the code yourself should be a straightforward case of:
  git clone git@github.com:irbouho/spring-cache-guava.git
  cd spring-cache-guava
  mvn install

To use Spring-Cache-Guava, you need to include the runtime module in the dependencies section of your pom.xml (replacing ${spring-cache-guava.version} with the appropriate current release):

  
    com.springmodules.cache.guava
    core
    ${spring-cache-guava.version}
  

Instances of GuavaCache can be created using Spring XML configuration:
  

This code snippet above creates an instance of the Guava cache factory bean using the default configuration. You can fine-tune the cache instance properties by providing a CacheBuilderSpec as follows:
  

GavaCaches need to be wrapped into a CacheManager to be used with Spring Cache Abstraction. Spring-Cache-Guava has a CacheManager that can be used to this end:

 
  
   
   
  
 




Now you have your CacheManager configured and Spring Framework caching annotations enabled. All you have to do is to create your beans and annotate them using Spring Framework Cache annotations.

  @Cacheable(value = "users-cache")
  public User findUserByUserName(String userName) {
    return userRepository.findByUserName(checkNotNull(userName));
  }

Spring-Guava-Cache

I had some free time recently and wrote a small adapter for Spring Framework Cache Abstraction backed by Google Guava Cache. I use both frameworks extensively and enjoy the features they provide.

The source code is available on GitHub. The Introduction page explains how to build the artifacts and use them in your project. You can use the Issues page to submit bugs / requests.

I will post more entries on this blog to explain more and share few lessons I learned.

Tuesday, June 12, 2007

Spring Modules Cache

Tutorials about configuring and using Spring Modules Cache.

Sunday, December 19, 2004

Caching the result of methods using Spring and EHCache

I published a new article on Spring Confluence Wiki that shows how to use Spring Integration for EHCache (since Spring 1.1.1).

The article presents a Spring Interceptor that caches methods results based on method name and arguments values. Of course the interceptor is configured declaratively using Spring IoC.