querqy.elasticsearch.Caches Maven / Gradle / Ivy
package querqy.elasticsearch;
import org.elasticsearch.common.cache.Cache;
import org.elasticsearch.common.cache.CacheBuilder;
import org.elasticsearch.core.TimeValue;
public class Caches {
public static Cache buildCache(final TimeValue expireAfterWrite, final TimeValue expireAfterAccess) {
final CacheBuilder builder = CacheBuilder.builder();
if (expireAfterWrite.nanos() > 0) {
builder.setExpireAfterWrite(expireAfterWrite);
}
if (expireAfterAccess.nanos() > 0) {
builder.setExpireAfterAccess(expireAfterAccess);
}
return builder.build();
}
}