Skip to content

Commit

Permalink
INTERNAL: provide meaningful methods instead of setters in ArcusCache…
Browse files Browse the repository at this point in the history
…Configuration
  • Loading branch information
oliviarla committed Sep 11, 2024
1 parent abe1739 commit 444f5f9
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 95 deletions.
73 changes: 34 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ public class ArcusConfiguration extends CachingConfigurerSupport {

@Bean
public ArcusCacheConfiguration defaultCacheConfig() {
ArcusCacheConfiguration defaultCacheConfig = new ArcusCacheConfiguration();
defaultCacheConfig.setPrefix("DEFAULT");
defaultCacheConfig.setExpireSeconds(60);
defaultCacheConfig.setTimeoutMilliSeconds(800);
return defaultCacheConfig;
return new ArcusCacheConfiguration()
.withPrefix("DEFAULT")
.withExpireSeconds(60)
.withTimeoutMilliSeconds(800);
}

@Bean
Expand All @@ -168,22 +167,20 @@ public class ArcusConfiguration extends CachingConfigurerSupport {

@Bean
public ArcusCacheConfiguration testCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("TEST-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(60);
cacheConfig.setTimeoutMilliSeconds(800);
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("TEST-")
.withPrefix("PRODUCT")
.withExpireSeconds(60)
.withTimeoutMillisSeconds(800);
}

@Bean
public ArcusCacheConfiguration devCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("DEV-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(120);
cacheConfig.setTimeoutMilliSeconds(800);
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("DEV-")
.withPrefix("PRODUCT")
.withExpireSeconds(120)
.withTimeoutMillisSeconds(800);
}

}
Expand Down Expand Up @@ -234,32 +231,30 @@ You can use the front cache to provide fast responsiveness of cache requests. Th
```java
@Bean
public ArcusCacheConfiguration testCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("TEST-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(60);
cacheConfig.setTimeoutMilliSeconds(800);
/* front cache configuration */
cacheConfig.setArcusFrontCache(testArcusFrontCache());
cacheConfig.setFrontExpireSeconds(120);
cacheConfig.setForceFrontCaching(false);
/* front cache configuration */
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("TEST-")
.withPrefix("PRODUCT")
.withExpireSeconds(60)
.withTimeoutMilliSeconds(800)
/* front cache configuration */
.withArcusFrontCache(testArcusFrontCache())
.withFrontExpireSeconds(120)
.withForceFrontCaching(false);
/* front cache configuration */
}

@Bean
public ArcusCacheConfiguration devCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("DEV-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(120);
cacheConfig.setTimeoutMilliSeconds(800);
/* front cache configuration */
cacheConfig.setArcusFrontCache(devArcusFrontCache());
cacheConfig.setFrontExpireSeconds(240);
cacheConfig.setForceFrontCaching(true);
/* front cache configuration */
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("DEV-")
.withPrefix("PRODUCT")
.withExpireSeconds(120)
.withTimeoutMilliSeconds(800)
/* front cache configuration */
.withArcusFrontCache(devArcusFrontCache())
.withFrontExpireSeconds(240)
.withForceFrontCaching(true);
/* front cache configuration */
}

@Bean
Expand Down
64 changes: 30 additions & 34 deletions docs/03-arcus-spring-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,20 @@ public class ArcusConfiguration extends CachingConfigurerSupport {

@Bean
public ArcusCacheConfiguration testCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("TEST-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(60);
cacheConfig.setTimeoutMilliSeconds(800);
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("TEST-")
.withPrefix("PRODUCT")
.withExpireSeconds(60)
.withTimeoutMilliSeconds(800);
}

@Bean
public ArcusCacheConfiguration devCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("DEV-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(120);
cacheConfig.setTimeoutMilliSeconds(800);
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("DEV-")
.withPrefix("PRODUCT")
.withExpireSeconds(120)
.withTimeoutMilliSeconds(800);
}
}
```
Expand Down Expand Up @@ -237,32 +235,30 @@ Front Cache 기능에 대한 설명은 [2장](02-arcus-spring-concept.md#front-c
```java
@Bean
public ArcusCacheConfiguration testCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("TEST-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(60);
cacheConfig.setTimeoutMilliSeconds(800);
/* front cache configuration */
cacheConfig.setArcusFrontCache(testArcusFrontCache());
cacheConfig.setFrontExpireSeconds(120);
cacheConfig.setForceFrontCaching(false);
/* front cache configuration */
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("TEST-")
.withPrefix("PRODUCT")
.withExpireSeconds(60)
.withTimeoutMilliSeconds(800)
/* front cache configuration */
.withArcusFrontCache(testArcusFrontCache())
.withFrontExpireSeconds(120)
.withForceFrontCaching(false);
/* front cache configuration */
}

@Bean
public ArcusCacheConfiguration devCacheConfig() {
ArcusCacheConfiguration cacheConfig = new ArcusCacheConfiguration();
cacheConfig.setServiceId("DEV-");
cacheConfig.setPrefix("PRODUCT");
cacheConfig.setExpireSeconds(120);
cacheConfig.setTimeoutMilliSeconds(800);
/* front cache configuration */
cacheConfig.setArcusFrontCache(devArcusFrontCache());
cacheConfig.setFrontExpireSeconds(240);
cacheConfig.setForceFrontCaching(true);
/* front cache configuration */
return cacheConfig;
return new ArcusCacheConfiguration()
.withServiceId("DEV-")
.withPrefix("PRODUCT")
.withExpireSeconds(120)
.withTimeoutMilliSeconds(800)
/* front cache configuration */
.withArcusFrontCache(devArcusFrontCache())
.withFrontExpireSeconds(240)
.withForceFrontCaching(true);
/* front cache configuration */
}

@Bean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,6 @@
@SuppressWarnings({"DeprecatedIsStillUsed", "deprecation"})
public class ArcusCache extends AbstractValueAdaptingCache {

public static final long DEFAULT_TIMEOUT_MILLISECONDS = 700L;
@Deprecated
public static final boolean DEFAULT_WANT_TO_GET_EXCEPTION = false;
public static final boolean DEFAULT_ALLOW_NULL_VALUES = true;

private final Logger logger = LoggerFactory.getLogger(this.getClass());

private String name;
Expand All @@ -97,7 +92,7 @@ public class ArcusCache extends AbstractValueAdaptingCache {
*/
@Deprecated
public ArcusCache() {
super(DEFAULT_ALLOW_NULL_VALUES);
super(ArcusCacheConfiguration.DEFAULT_ALLOW_NULL_VALUES);
this.configuration = new ArcusCacheConfiguration();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,97 @@

import net.spy.memcached.transcoders.Transcoder;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;

@SuppressWarnings("DeprecatedIsStillUsed")
public class ArcusCacheConfiguration implements InitializingBean {
public class ArcusCacheConfiguration {

static final long DEFAULT_TIMEOUT_MILLISECONDS = 700L;
@Deprecated
static final boolean DEFAULT_WANT_TO_GET_EXCEPTION = false;
static final boolean DEFAULT_ALLOW_NULL_VALUES = true;

private String serviceId = "";
@Nullable
private String prefix;
private int expireSeconds;
private int frontExpireSeconds;
private long timeoutMilliSeconds = ArcusCache.DEFAULT_TIMEOUT_MILLISECONDS;
private long timeoutMilliSeconds = DEFAULT_TIMEOUT_MILLISECONDS;
@Nullable
private Transcoder<Object> operationTranscoder;
@Nullable
private ArcusFrontCache arcusFrontCache;
@Deprecated
private boolean wantToGetException = ArcusCache.DEFAULT_WANT_TO_GET_EXCEPTION;
private int frontExpireSeconds = 5;
private boolean forceFrontCaching;
private boolean allowNullValues = ArcusCache.DEFAULT_ALLOW_NULL_VALUES;
@Deprecated
private boolean wantToGetException = DEFAULT_WANT_TO_GET_EXCEPTION;
private boolean allowNullValues = DEFAULT_ALLOW_NULL_VALUES;

public ArcusCacheConfiguration() {
}

public ArcusCacheConfiguration withServiceId(String serviceId) {
Assert.notNull(serviceId, "ServiceId must not be null.");
this.serviceId = serviceId;
return this;
}

public ArcusCacheConfiguration withPrefix(String prefix) {
Assert.notNull(prefix, "Prefix must not be null.");
this.prefix = prefix;
return this;
}

public ArcusCacheConfiguration withExpireSeconds(int expireSeconds) {
Assert.isTrue(expireSeconds > -2, "ExpireSeconds must be positive integer, 0, or -1.");
this.expireSeconds = expireSeconds;
return this;
}

public ArcusCacheConfiguration withTimeoutMilliSeconds(long timeoutMilliSeconds) {
Assert.isTrue(timeoutMilliSeconds > 0, "TimeoutMilliSeconds must be larger than 0.");
this.timeoutMilliSeconds = timeoutMilliSeconds;
return this;
}

public ArcusCacheConfiguration withOperationTranscoder(Transcoder<Object> operationTranscoder) {
Assert.notNull(operationTranscoder, "OperationTranscoder must not be null.");
this.operationTranscoder = operationTranscoder;
return this;
}

public ArcusCacheConfiguration withArcusFrontCache(ArcusFrontCache arcusFrontCache) {
Assert.notNull(arcusFrontCache, "ArcusFrontCache must not be null.");
this.arcusFrontCache = arcusFrontCache;
return this;
}

public ArcusCacheConfiguration withFrontExpireSeconds(int frontExpireSeconds) {
Assert.isTrue(frontExpireSeconds > -1, "FrontExpireSeconds must not be negative integer.");
this.frontExpireSeconds = frontExpireSeconds;
return this;
}

public ArcusCacheConfiguration enableForcingFrontCaching() {
this.forceFrontCaching = true;
return this;
}

@Deprecated
public ArcusCacheConfiguration enableGettingException() {
this.wantToGetException = true;
return this;
}

public ArcusCacheConfiguration disableCachingNullValues() {
this.allowNullValues = false;
return this;
}

public String getServiceId() {
return serviceId;
}

@Deprecated
public void setServiceId(String serviceId) {
this.serviceId = serviceId;
}
Expand All @@ -54,6 +123,7 @@ public String getPrefix() {
return prefix;
}

@Deprecated
public void setPrefix(@Nullable String prefix) {
this.prefix = prefix;
}
Expand All @@ -62,6 +132,7 @@ public int getExpireSeconds() {
return expireSeconds;
}

@Deprecated
public void setExpireSeconds(int expireSeconds) {
this.expireSeconds = expireSeconds;
}
Expand All @@ -70,6 +141,7 @@ public int getFrontExpireSeconds() {
return frontExpireSeconds;
}

@Deprecated
public void setFrontExpireSeconds(int frontExpireSeconds) {
this.frontExpireSeconds = frontExpireSeconds;
}
Expand All @@ -78,7 +150,9 @@ public long getTimeoutMilliSeconds() {
return timeoutMilliSeconds;
}

@Deprecated
public void setTimeoutMilliSeconds(long timeoutMilliSeconds) {
Assert.isTrue(timeoutMilliSeconds > 0, "TimeoutMilliSeconds must be larger than 0.");
this.timeoutMilliSeconds = timeoutMilliSeconds;
}

Expand All @@ -87,6 +161,7 @@ public Transcoder<Object> getOperationTranscoder() {
return operationTranscoder;
}

@Deprecated
public void setOperationTranscoder(@Nullable Transcoder<Object> operationTranscoder) {
this.operationTranscoder = operationTranscoder;
}
Expand All @@ -96,6 +171,7 @@ public ArcusFrontCache getArcusFrontCache() {
return arcusFrontCache;
}

@Deprecated
public void setArcusFrontCache(@Nullable ArcusFrontCache arcusFrontCache) {
this.arcusFrontCache = arcusFrontCache;
}
Expand All @@ -114,6 +190,7 @@ public boolean isForceFrontCaching() {
return forceFrontCaching;
}

@Deprecated
public void setForceFrontCaching(boolean forceFrontCaching) {
this.forceFrontCaching = forceFrontCaching;
}
Expand All @@ -122,13 +199,9 @@ public boolean isAllowNullValues() {
return this.allowNullValues;
}

@Deprecated
public void setAllowNullValues(boolean allowNullValues) {
this.allowNullValues = allowNullValues;
}

@Override
public void afterPropertiesSet() {
Assert.isTrue(timeoutMilliSeconds > 0, "TimeoutMilliSeconds must be larger than 0.");
}

}
Loading

0 comments on commit 444f5f9

Please sign in to comment.