jsr107-magnolia
See
After installation you can cache the result of any method of any guice managed bean by adding the @CacheResult
annotation.
@CacheResult(cacheName = "CinemaUtil-sortedMovies")
public List<Map.Entry<Movie, Set<RoleType>>> sortedMovies(Person person) {
...
}
In this case in the magnolia cache configuration automaticly a cache 'CinemaUtil-sortedMovies' will appear.
Possible cache values
The cache values may be null
and Optional
. This implementation will arrange that no nulls are stored in the underlying magnolia cache. If the value is Optional
, the value of the Optional
will be serialized.
Non serializable values are only possible if the underlying eh-cache is configured not to store to disk.
Model classes
Sadly, model classes are not instantiated by guice, but by Magnolia itself, so they cannot be proxied by guice.
##Installation
Download the most recent jar from: https://oss.sonatype.org/content/repositories/snapshots/nl/vpro/jsr107-magnolia and install it like you'd normally would.
Or you can add this to your pom.xml
<dependency>
<groupId>nl.vpro</groupId>
<artifactId>jsr107-magnolia</artifactId>
<version>1.4</version>
</dependency>
###Configuration You can configure the create cache like so in the JCR-tree:
Cache-configurations can be automaticly created like this using tasks on the version handler of your module. E.g.
@Slf4j
public class CinemaVersionHandler extends DefaultModuleVersionHandler {
@Override
protected List<Task> getBasicInstallTasks(InstallContext installContext) {
List<Task> tasks = super.getBasicInstallTasks(installContext);
tasks.addAll(CreateConfigurationTasks.createConfigurationTasks(CinemaUtilWithCaching.class));
log.info("Created tasks {}", tasks);
return tasks;
}
}