Support for setting diskLimit from CacheModule bindings
For some persistent caches we may want a larger default diskLimit than the overall default of 128MiB. Change-Id: I9f8c85d7187d2edfe5ba48ea27c7b5f5e37e7abe
This commit is contained in:
parent
2c55373946
commit
9c87603a8b
@ -178,7 +178,7 @@ class H2CacheFactory implements PersistentCacheFactory, LifecycleListener {
|
|||||||
public <K, V> LoadingCache<K, V> build(
|
public <K, V> LoadingCache<K, V> build(
|
||||||
CacheBinding<K, V> def,
|
CacheBinding<K, V> def,
|
||||||
CacheLoader<K, V> loader) {
|
CacheLoader<K, V> loader) {
|
||||||
long limit = config.getLong("cache", def.name(), "diskLimit", 128 << 20);
|
long limit = config.getLong("cache", def.name(), "diskLimit", def.diskLimit());
|
||||||
|
|
||||||
if (cacheDir == null || limit <= 0) {
|
if (cacheDir == null || limit <= 0) {
|
||||||
return defaultFactory.build(def, loader);
|
return defaultFactory.build(def, loader);
|
||||||
|
@ -26,6 +26,9 @@ public interface CacheBinding<K, V> {
|
|||||||
/** Set the total size of the cache. */
|
/** Set the total size of the cache. */
|
||||||
CacheBinding<K, V> maximumWeight(long weight);
|
CacheBinding<K, V> maximumWeight(long weight);
|
||||||
|
|
||||||
|
/** Set the total on-disk limit of the cache */
|
||||||
|
CacheBinding<K, V> diskLimit(long limit);
|
||||||
|
|
||||||
/** Set the time an element lives before being expired. */
|
/** Set the time an element lives before being expired. */
|
||||||
CacheBinding<K, V> expireAfterWrite(long duration, TimeUnit durationUnits);
|
CacheBinding<K, V> expireAfterWrite(long duration, TimeUnit durationUnits);
|
||||||
|
|
||||||
@ -39,6 +42,7 @@ public interface CacheBinding<K, V> {
|
|||||||
TypeLiteral<K> keyType();
|
TypeLiteral<K> keyType();
|
||||||
TypeLiteral<V> valueType();
|
TypeLiteral<V> valueType();
|
||||||
long maximumWeight();
|
long maximumWeight();
|
||||||
|
long diskLimit();
|
||||||
@Nullable Long expireAfterWrite(TimeUnit unit);
|
@Nullable Long expireAfterWrite(TimeUnit unit);
|
||||||
@Nullable Weigher<K, V> weigher();
|
@Nullable Weigher<K, V> weigher();
|
||||||
@Nullable CacheLoader<K, V> loader();
|
@Nullable CacheLoader<K, V> loader();
|
||||||
|
@ -38,6 +38,7 @@ class CacheProvider<K, V>
|
|||||||
private final TypeLiteral<V> valType;
|
private final TypeLiteral<V> valType;
|
||||||
private boolean persist;
|
private boolean persist;
|
||||||
private long maximumWeight;
|
private long maximumWeight;
|
||||||
|
private long diskLimit;
|
||||||
private Long expireAfterWrite;
|
private Long expireAfterWrite;
|
||||||
private Provider<CacheLoader<K, V>> loader;
|
private Provider<CacheLoader<K, V>> loader;
|
||||||
private Provider<Weigher<K, V>> weigher;
|
private Provider<Weigher<K, V>> weigher;
|
||||||
@ -85,6 +86,15 @@ class CacheProvider<K, V>
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CacheBinding<K, V> diskLimit(long limit) {
|
||||||
|
Preconditions.checkState(!frozen, "binding frozen, cannot be modified");
|
||||||
|
Preconditions.checkState(persist,
|
||||||
|
"diskLimit supported for persistent caches only");
|
||||||
|
diskLimit = limit;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CacheBinding<K, V> expireAfterWrite(long duration, TimeUnit unit) {
|
public CacheBinding<K, V> expireAfterWrite(long duration, TimeUnit unit) {
|
||||||
Preconditions.checkState(!frozen, "binding frozen, cannot be modified");
|
Preconditions.checkState(!frozen, "binding frozen, cannot be modified");
|
||||||
@ -129,6 +139,14 @@ class CacheProvider<K, V>
|
|||||||
return maximumWeight;
|
return maximumWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long diskLimit() {
|
||||||
|
if (diskLimit > 0) {
|
||||||
|
return diskLimit;
|
||||||
|
}
|
||||||
|
return 128 << 20;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public Long expireAfterWrite(TimeUnit unit) {
|
public Long expireAfterWrite(TimeUnit unit) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user