Merge "Make H2 database cache size configurable"
This commit is contained in:
@@ -528,6 +528,20 @@ If not absolute, the path is resolved relative to `$site_path`.
|
|||||||
+
|
+
|
||||||
Default is unset, no disk cache.
|
Default is unset, no disk cache.
|
||||||
|
|
||||||
|
[[cache.h2CacheSize]]cache.h2CacheSize::
|
||||||
|
+
|
||||||
|
The size of the H2 database cache, in bytes, used for each persistent cache.
|
||||||
|
This can be used to limit the H2 cache size and thus prevent out-of-memory
|
||||||
|
caused by the H2 database using too much memory.
|
||||||
|
+
|
||||||
|
Technically the H2 cache size is configured using the CACHE_SIZE parameter in
|
||||||
|
the H2 JDBC connection URL, as described
|
||||||
|
link:http://www.h2database.com/html/features.html#cache_settings[here]
|
||||||
|
+
|
||||||
|
Default is unset, no cache size limit.
|
||||||
|
+
|
||||||
|
Common unit suffixes of 'k', 'm', or 'g' are supported.
|
||||||
|
|
||||||
[[cache.name.maxAge]]cache.<name>.maxAge::
|
[[cache.name.maxAge]]cache.<name>.maxAge::
|
||||||
+
|
+
|
||||||
Maximum age to keep an entry in the cache. Entries are removed from
|
Maximum age to keep an entry in the cache. Entries are removed from
|
||||||
|
@@ -58,6 +58,7 @@ class H2CacheFactory implements PersistentCacheFactory, LifecycleListener {
|
|||||||
private final DynamicMap<Cache<?, ?>> cacheMap;
|
private final DynamicMap<Cache<?, ?>> cacheMap;
|
||||||
private final ExecutorService executor;
|
private final ExecutorService executor;
|
||||||
private final ScheduledExecutorService cleanup;
|
private final ScheduledExecutorService cleanup;
|
||||||
|
private final long h2CacheSize;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
H2CacheFactory(
|
H2CacheFactory(
|
||||||
@@ -68,6 +69,7 @@ class H2CacheFactory implements PersistentCacheFactory, LifecycleListener {
|
|||||||
defaultFactory = defaultCacheFactory;
|
defaultFactory = defaultCacheFactory;
|
||||||
config = cfg;
|
config = cfg;
|
||||||
cacheDir = getCacheDir(site, cfg.getString("cache", null, "directory"));
|
cacheDir = getCacheDir(site, cfg.getString("cache", null, "directory"));
|
||||||
|
h2CacheSize = cfg.getLong("cache", null, "h2CacheSize", -1);
|
||||||
caches = Lists.newLinkedList();
|
caches = Lists.newLinkedList();
|
||||||
this.cacheMap = cacheMap;
|
this.cacheMap = cacheMap;
|
||||||
|
|
||||||
@@ -220,8 +222,14 @@ class H2CacheFactory implements PersistentCacheFactory, LifecycleListener {
|
|||||||
TypeLiteral<K> keyType,
|
TypeLiteral<K> keyType,
|
||||||
long maxSize,
|
long maxSize,
|
||||||
Long expireAfterWrite) {
|
Long expireAfterWrite) {
|
||||||
String url = "jdbc:h2:" + cacheDir.resolve(name).toUri();
|
StringBuilder url = new StringBuilder();
|
||||||
return new SqlStore<>(url, keyType, maxSize,
|
url.append("jdbc:h2:").append(cacheDir.resolve(name).toUri());
|
||||||
|
if (h2CacheSize >= 0) {
|
||||||
|
url.append(";CACHE_SIZE=");
|
||||||
|
// H2 CACHE_SIZE is always given in KB
|
||||||
|
url.append(h2CacheSize / 1024);
|
||||||
|
}
|
||||||
|
return new SqlStore<>(url.toString(), keyType, maxSize,
|
||||||
expireAfterWrite == null ? 0 : expireAfterWrite.longValue());
|
expireAfterWrite == null ? 0 : expireAfterWrite.longValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user