Skip to content

Commit 07bb3a5

Browse files
committed
Extract duplicate duration validation logic to helper method
- Add isPositiveDuration(Duration) helper method - Replace duplicate validation logic at lines 215 and 566 - Improve code maintainability and readability Signed-off-by: bread <thayer2392@gmail.com>
1 parent 19573e2 commit 07bb3a5

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/main/java/org/springframework/data/redis/cache/DefaultRedisCacheWriter.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public void enable(Consumer<CacheLockingConfiguration> configurationConsumer) {
212212
public CacheLockingConfiguration sleepTime(Duration sleepTime) {
213213

214214
Assert.notNull(sleepTime, "Lock sleep time must not be null");
215-
Assert.isTrue(!sleepTime.isZero() && !sleepTime.isNegative(),
215+
Assert.isTrue(isPositiveDuration(sleepTime),
216216
"Lock sleep time must not be null zero or negative");
217217

218218
this.lockSleepTime = sleepTime;
@@ -563,7 +563,7 @@ private <T> T executeLockFree(Function<RedisConnection, T> callback) {
563563
* @return {@literal true} if {@link RedisCacheWriter} uses locks.
564564
*/
565565
private boolean isLockingCacheWriter() {
566-
return !this.sleepTime.isZero() && !this.sleepTime.isNegative();
566+
return isPositiveDuration(this.sleepTime);
567567
}
568568

569569
private void checkAndPotentiallyWaitUntilUnlocked(String name, RedisConnection connection) {
@@ -601,6 +601,10 @@ private static boolean shouldExpireWithin(@Nullable Duration ttl) {
601601
return ttl != null && !ttl.isZero() && !ttl.isNegative();
602602
}
603603

604+
private static boolean isPositiveDuration(Duration duration) {
605+
return !duration.isZero() && !duration.isNegative();
606+
}
607+
604608
/**
605609
* Interface for asynchronous cache retrieval.
606610
*

0 commit comments

Comments
 (0)