Following the spring documentation about cache I could use cache on my project, but how can I configure guava to define a expired time or size per cache name?
applicationConfig.xml
<bean id="cacheManager" class="org.springframework.cache.guava.GuavaCacheManager"/>
Foo.java
@Cacheable(value="courses", key="#user.id")
public List<Course> getCoursesByUser(User user) {
...
}
You can configure caches separately. See Spring Guava cache
I think that @mavarazy answer is the best. I only add if you need you own automatic missed cache configuration you could do it on the following way.
First define you own cache manager which creates automatically cache if you need it:
And now you can define cache manager configuration:
You can specify CacheBuilder for your GuavaCacheManager in your Spring configuration
For more information look at:
http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/cache/CacheBuilderSpec.html
Injecting Google guava cache builder into bean via Spring
In another way
XML
Java