Skip to content

Commit

Permalink
Minor change
Browse files Browse the repository at this point in the history
Signed-off-by: Paolo Di Tommaso <[email protected]>
  • Loading branch information
pditommaso committed Jan 28, 2025
1 parent 2fd4721 commit 58cf2ea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -110,10 +111,30 @@ abstract class AbstractTieredCache<V extends MoshiExchange> 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()
}
Expand Down Expand Up @@ -302,7 +323,7 @@ abstract class AbstractTieredCache<V extends MoshiExchange> 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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}
}

0 comments on commit 58cf2ea

Please sign in to comment.