public class Eh extends Object implements Jooby.Module
Provides advanced cache features via Ehcache
CacheManagerEhcache instances
{
use(new Eh());
get("/", req -> {
CacheManager cm = req.require(CacheManager.class);
// work with cm
Ehcache ehcache = req.require(Ehcache.class);
// work with ehcache
});
}
Ehcache can be fully configured from your .conf
file and/or programmatically but for the time being there is no support for xml.
Caches are configured via .conf like almost everything in Jooby.
ehcache.cache.mycache {
eternal = true
}
Later, we can access to mycache with:
{
get("/", req -> {
Ehcache mycache = req.require(Ehcache.class);
});
}
Multiple caches are also possible:
ehcache.cache.cache1 {
maxEntriesLocalHeap = 100
eternal = true
}
ehcache.cache.cache2 {
maxEntriesLocalHeap = 100
eternal = true
}
Later, we can access to our caches with:
{
get("/", req -> {
Ehcache cache1 = req.require("cache1", Ehcache.class);
// ..
Ehcache cache2 = req.require("cache2", Ehcache.class);
// ..
});
}
Previous examples, show how to configure two or more caches, but it is also possible to inherit
cache configuration using the default cache:
ehcache.cache.default {
maxEntriesLocalHeap = 100
eternal = true
}
ehcache.cache.cache1 {
eternal = false
}
ehcache.cache.cache2 {
maxEntriesLocalHeap = 1000
}
Here cache1 and cache2 will inherited their properties from the
default cache.
Please note the default cache works as a template and isn't a real/usable cache.
This module provides an EhSessionStore. In order to use the EhSessionStore all
you have to do is define a session cache:
ehcache.cache.session {
# cache will expire after 30 minutes of inactivity
timeToIdle = 30m
}
And then register the EhSessionStore:
{
session(EhSessionStore.class);
}
Configuration is done in one of two ways: 1) via .conf; or 2)
programmatically:.
ehcache {
defaultTransactionTimeout = 1m
dynamicConfig = true
maxBytesLocalDisk = 1k
maxBytesLocalHeap = 1k
maxBytesLocalOffHeap = 1m
monitor = off
# just one event listener
cacheManagerEventListenerFactory {
class = MyCacheEventListenerFactory
p1 = "v1"
p2 = true
}
# or multiple event listeners
cacheManagerEventListenerFactory {
listener1 {
class = MyCacheEventListenerFactory1
p1 = "v1"
p2 = true
}
listener2 {
class = MyCacheEventListenerFactory2
}
}
diskStore.path = ${application.tmpdir}${file.separator}ehcache
# etc...
}
{
use(new Eh().doWith(conf -> {
conf.setDefaultTransactionTimeoutInSeconds(120);
// etc...
}));
}
| Constructor and Description |
|---|
Eh() |
| Modifier and Type | Method and Description |
|---|---|
com.typesafe.config.Config |
config() |
void |
configure(Env env,
com.typesafe.config.Config config,
com.google.inject.Binder binder) |
Eh |
doWith(BiConsumer<net.sf.ehcache.config.Configuration,com.typesafe.config.Config> configurer)
Configure callback to manipulate a
Configuration programmatically. |
Eh |
doWith(Consumer<net.sf.ehcache.config.Configuration> configurer)
Configure callback to manipulate a
Configuration programmatically. |
public void configure(Env env, com.typesafe.config.Config config, com.google.inject.Binder binder)
configure in interface Jooby.Modulepublic Eh doWith(BiConsumer<net.sf.ehcache.config.Configuration,com.typesafe.config.Config> configurer)
Configuration programmatically.configurer - A configure callback.Eh cache.public Eh doWith(Consumer<net.sf.ehcache.config.Configuration> configurer)
Configuration programmatically.configurer - A configure callback.Eh cache.public com.typesafe.config.Config config()
config in interface Jooby.ModuleCopyright © 2021. All rights reserved.