Skip to content

Commit

Permalink
Merge pull request #145 from Netflix/evcache-builder-pool-manager
Browse files Browse the repository at this point in the history
Expose a setter in EVCache.Builder to explicitly set the pool manager
  • Loading branch information
asibross authored May 30, 2024
2 parents 164af4b + c9e9a64 commit 7b54d1b
Showing 1 changed file with 74 additions and 64 deletions.
138 changes: 74 additions & 64 deletions evcache-core/src/main/java/com/netflix/evcache/EVCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -1236,12 +1236,12 @@ public Builder() {
}

public Builder withConfigurationProperties(
final EVCacheClientPoolConfigurationProperties configurationProperties) {
return this
.setCachePrefix(configurationProperties.getKeyPrefix())
.setDefaultTTL(configurationProperties.getTimeToLive())
.setRetry(configurationProperties.getRetryEnabled())
.setExceptionThrowing(configurationProperties.getExceptionThrowingEnabled());
final EVCacheClientPoolConfigurationProperties configurationProperties) {
return this
.setCachePrefix(configurationProperties.getKeyPrefix())
.setDefaultTTL(configurationProperties.getTimeToLive())
.setRetry(configurationProperties.getRetryEnabled())
.setExceptionThrowing(configurationProperties.getExceptionThrowingEnabled());
}

/**
Expand Down Expand Up @@ -1304,15 +1304,15 @@ public Builder setDefaultTTL(int ttl) {
return this;
}

/**
* The default Time To Live (TTL) for items in {@link EVCache} in
* seconds. You can override the value by passing the desired TTL with
* {@link EVCache#set(String, Object, int)} operations.
*
* @param ttl. Default is 900 seconds.
* @return this {@code Builder} object
*/
public Builder setDefaultTTL(@Nullable final Duration ttl) {
/**
* The default Time To Live (TTL) for items in {@link EVCache} in
* seconds. You can override the value by passing the desired TTL with
* {@link EVCache#set(String, Object, int)} operations.
*
* @param ttl. Default is 900 seconds.
* @return this {@code Builder} object
*/
public Builder setDefaultTTL(@Nullable final Duration ttl) {
if (ttl == null) {
return this;
}
Expand All @@ -1322,7 +1322,7 @@ public Builder setDefaultTTL(@Nullable final Duration ttl) {

@VisibleForTesting
Transcoder<?> getTranscoder() {
return this._transcoder;
return this._transcoder;
}

/**
Expand All @@ -1349,18 +1349,18 @@ public <T> Builder enableZoneFallback() {
return this;
}

/**
* Will enable or disable retry across Server Group for cache misses and exceptions
* if there are multiple Server Groups for the given EVCache App and
* data is replicated across them. This ensures the Hit Rate continues
* to be unaffected whenever a server group loses instances.
*
* By Default retry is enabled.
*
* @param enableRetry whether retries are to be enabled
* @return this {@code Builder} object
*/
public Builder setRetry(boolean enableRetry) {
/**
* Will enable or disable retry across Server Group for cache misses and exceptions
* if there are multiple Server Groups for the given EVCache App and
* data is replicated across them. This ensures the Hit Rate continues
* to be unaffected whenever a server group loses instances.
*
* By Default retry is enabled.
*
* @param enableRetry whether retries are to be enabled
* @return this {@code Builder} object
*/
public Builder setRetry(boolean enableRetry) {
this._serverGroupRetry = enableRetry;

return this;
Expand Down Expand Up @@ -1404,15 +1404,15 @@ public <T> Builder disableZoneFallback() {
return this;
}

/**
* By Default exceptions are not propagated and null values are
* returned. By enabling exception propagation we return the
* {@link EVCacheException} whenever the operations experience them.
*
* @param enableExceptionThrowing whether exception throwing is to be enabled
* @return this {@code Builder} object
*/
public Builder setExceptionThrowing(boolean enableExceptionThrowing) {
/**
* By Default exceptions are not propagated and null values are
* returned. By enabling exception propagation we return the
* {@link EVCacheException} whenever the operations experience them.
*
* @param enableExceptionThrowing whether exception throwing is to be enabled
* @return this {@code Builder} object
*/
public Builder setExceptionThrowing(boolean enableExceptionThrowing) {
this._enableExceptionThrowing = enableExceptionThrowing;

return this;
Expand All @@ -1430,46 +1430,56 @@ public <T> Builder enableExceptionPropagation() {
return this;
}

/**
* Adds customizers to be applied by {@code customize}.
*
* @param customizers List of {@code Customizer}s
* @return this {@code Builder} object
*/
/**
* Adds customizers to be applied by {@code customize}.
*
* @param customizers List of {@code Customizer}s
* @return this {@code Builder} object
*/
public Builder addCustomizers(@Nullable final List<Customizer> customizers) {
this._customizers.addAll(customizers);

return this;
}


/**
* Applies {@code Customizer}s added through {@code addCustomizers} to {@this}.
*
* @return this {@code Builder} object
*/
public Builder customize() {
_customizers.forEach(customizer -> {
customizeWith(customizer);
});

return this;
}

/**
* Customizes {@this} with the {@code customizer}.
*
* @param customizer {@code Customizer} or {@code Consumer<String, Builder>} to be applied to {@code this}.
* @return this {@code Builder} object
*/
public Builder customizeWith(final Customizer customizer) {
/**
* Applies {@code Customizer}s added through {@code addCustomizers} to {@this}.
*
* @return this {@code Builder} object
*/
public Builder customize() {
_customizers.forEach(customizer -> {
customizeWith(customizer);
});

return this;
}

/**
* Customizes {@this} with the {@code customizer}.
*
* @param customizer {@code Customizer} or {@code Consumer<String, Builder>} to be applied to {@code this}.
* @return this {@code Builder} object
*/
public Builder customizeWith(final Customizer customizer) {
customizer.customize(this._appName, this);

return this;
}

/**
* The EVCache pool manager that will be used by this {@code EVCache}.
* @param poolManager
* @return this {@code Builder} object
*/
public Builder setPoolManager(EVCacheClientPoolManager poolManager) {
_poolManager = poolManager;
return this;
}

protected EVCache newImpl(String appName, String cachePrefix, int ttl, Transcoder<?> transcoder, boolean serverGroupRetry, boolean enableExceptionThrowing, EVCacheClientPoolManager poolManager) {
return new EVCacheImpl(appName, cachePrefix, ttl, transcoder, serverGroupRetry, enableExceptionThrowing, poolManager);
return new EVCacheImpl(appName, cachePrefix, ttl, transcoder, serverGroupRetry, enableExceptionThrowing, poolManager);
}

/**
Expand Down

0 comments on commit 7b54d1b

Please sign in to comment.