Allow persistent caches to be not persisted by default

H2CacheFactory already respected a non-positive value and disabled
persistence when explicitly configured in gerrit.config. However, the
implementation of PersistentCacheProvider would never return a
non-positive value from diskLimit(), so it was impossible to disable
persistence by default. Fix this so PersistentCacheProvider uses 128 MiB
when the instance is created, but allow overriding with a non-positive
value.

Change-Id: I189f6dad2003c8bb8ba6e05705e2903c099759c3
This commit is contained in:
Dave Borowitz
2018-05-14 16:35:37 -07:00
parent acbf3abd12
commit dab5155259
3 changed files with 9 additions and 6 deletions

View File

@@ -776,7 +776,7 @@ Default is 128 MiB per cache, except:
* `"diff_summary"`: default is `1g` (1 GiB of disk space)
+
If 0, disk storage for the cache is disabled.
If 0 or negative, disk storage for the cache is disabled.
==== [[cache_names]]Standard Caches

View File

@@ -34,7 +34,12 @@ public interface PersistentCacheBinding<K, V> extends CacheBinding<K, V> {
PersistentCacheBinding<K, V> version(int version);
/** Set the total on-disk limit of the cache */
/**
* Set the total on-disk limit of the cache.
*
* <p>If 0 or negative, persistence for the cache is disabled by default, but may still be
* overridden in the config.
*/
PersistentCacheBinding<K, V> diskLimit(long limit);
PersistentCacheBinding<K, V> keySerializer(CacheSerializer<K> keySerializer);

View File

@@ -39,6 +39,7 @@ class PersistentCacheProvider<K, V> extends CacheProvider<K, V>
CacheModule module, String name, TypeLiteral<K> keyType, TypeLiteral<V> valType) {
super(module, name, keyType, valType);
version = -1;
diskLimit = 128 << 20;
}
@Inject(optional = true)
@@ -93,10 +94,7 @@ class PersistentCacheProvider<K, V> extends CacheProvider<K, V>
@Override
public long diskLimit() {
if (diskLimit > 0) {
return diskLimit;
}
return 128 << 20;
return diskLimit;
}
@Override