From 58cf2ea0774df7ffef73c5bb399ed863fd247cf3 Mon Sep 17 00:00:00 2001 From: Paolo Di Tommaso Date: Tue, 28 Jan 2025 11:37:33 +0100 Subject: [PATCH] Minor change Signed-off-by: Paolo Di Tommaso --- .../store/cache/AbstractTieredCache.groovy | 23 ++++++++++++++++++- .../cache/AbstractTieredCacheTest.groovy | 11 --------- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/main/groovy/io/seqera/wave/store/cache/AbstractTieredCache.groovy b/src/main/groovy/io/seqera/wave/store/cache/AbstractTieredCache.groovy index 4b6217bc3..e0513cbfb 100644 --- a/src/main/groovy/io/seqera/wave/store/cache/AbstractTieredCache.groovy +++ b/src/main/groovy/io/seqera/wave/store/cache/AbstractTieredCache.groovy @@ -33,6 +33,7 @@ import com.github.benmanes.caffeine.cache.RemovalCause import com.github.benmanes.caffeine.cache.RemovalListener import groovy.transform.Canonical import groovy.transform.CompileStatic +import groovy.transform.Memoized import groovy.transform.ToString import groovy.util.logging.Slf4j import io.seqera.wave.encoder.EncodingStrategy @@ -110,10 +111,30 @@ abstract class AbstractTieredCache implements TieredCac abstract protected String getPrefix() + /** + * The cache probabilistic revalidation internal. + * + * See https://blog.cloudflare.com/sometimes-i-cache/ + * + * @return + * The cache cache revalidation internal as a {@link Duration} value. + * When {@link Duration#ZERO} probabilistic revalidation is disabled. + */ protected Duration getCacheRevalidationInterval() { return Duration.ZERO } + /** + * The cache probabilistic revalidation steepness value. + * + * By default is implemented as 1 / {@link #getCacheRevalidationInterval()} (as millis). + * Subclasses can override this method to provide a different value. + * + * See https://blog.cloudflare.com/sometimes-i-cache/ + * + * @return Returns the revalidation steepness value. + */ + @Memoized protected double getRevalidationSteepness() { return 1 / getCacheRevalidationInterval().toMillis() } @@ -302,7 +323,7 @@ abstract class AbstractTieredCache implements TieredCac // otherwise, when remaining is greater than the cache revalidation interval // no revalidation is needed final cacheRevalidationMills = cacheRevalidationInterval.toMillis() - if( remainingCacheTime > cacheRevalidationMills ) { + if( cacheRevalidationMills < remainingCacheTime ) { return false } diff --git a/src/test/groovy/io/seqera/wave/store/cache/AbstractTieredCacheTest.groovy b/src/test/groovy/io/seqera/wave/store/cache/AbstractTieredCacheTest.groovy index a76c0444e..c2edc8b5b 100644 --- a/src/test/groovy/io/seqera/wave/store/cache/AbstractTieredCacheTest.groovy +++ b/src/test/groovy/io/seqera/wave/store/cache/AbstractTieredCacheTest.groovy @@ -290,11 +290,6 @@ class AbstractTieredCacheTest extends Specification implements RedisTestContaine // the function should return true cache.randomRevalidate(10) // 10 millis cache.randomRevalidate(100) // 100 millis - and: - // when it's mostly the same as the revalidation interval - // it should return false - !cache.randomRevalidate(9_000) - !cache.randomRevalidate(10_000) } @Retry(count = 5) @@ -309,11 +304,5 @@ class AbstractTieredCacheTest extends Specification implements RedisTestContaine cache.randomRevalidate(10) // 10 millis cache.randomRevalidate(100) // 100 millis cache.randomRevalidate(500) // 100 millis - and: - // when it's mostly the same as the revalidation interval - // it should return false - !cache.randomRevalidate(250_000) - !cache.randomRevalidate(290_000) - !cache.randomRevalidate(300_000) } }