Skip to content

Commit

Permalink
Merge pull request #204 from blemale/Update_caffeine_to_2_9_1
Browse files Browse the repository at this point in the history
Update caffeine to 2.9.1
  • Loading branch information
blemale committed Jun 5, 2021
2 parents 6f3c10a + b650b04 commit 0795898
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Expand Up @@ -2,13 +2,16 @@
# Simple Build Tool
# http://www.scala-sbt.org/release/docs/Getting-Started/Directories.html#configuring-version-control

dist/*
target/
lib_managed/
src_managed/
project/boot/
project/plugins/project/
.history
.cache

.lib/
.bsp

### Intellij ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
Expand Down
6 changes: 5 additions & 1 deletion build.sbt
Expand Up @@ -28,7 +28,11 @@ libraryDependencies ++=
"org.scala-lang.modules" %% "scala-java8-compat" % "1.0.0",
"com.google.code.findbugs" % "jsr305" % "3.0.2" % "provided",
"org.scalactic" %% "scalactic" % "3.2.9" % "test",
"org.scalatest" %% "scalatest" % "3.2.9" % "test"
"org.scalatest" %% "scalatest" % "3.2.9" % "test",
compilerPlugin(
"com.github.ghik" % "silencer-plugin" % "1.7.5" cross CrossVersion.full
),
"com.github.ghik" % "silencer-lib" % "1.7.5" % Provided cross CrossVersion.full
)

scalafmtOnCompile := true
Expand Down
2 changes: 1 addition & 1 deletion project/CaffeineVersion.scala
@@ -1,5 +1,5 @@
object CaffeineVersion {

val value: String = "2.8.5"
val value: String = "2.9.1"

}
31 changes: 28 additions & 3 deletions src/main/scala/com/github/blemale/scaffeine/Scaffeine.scala
@@ -1,12 +1,12 @@
package com.github.blemale.scaffeine

import java.util.concurrent.{CompletableFuture, Executor}
import java.{lang, util}

import com.github.benmanes.caffeine
import com.github.benmanes.caffeine.cache.Scheduler
import com.github.benmanes.caffeine.cache.stats.StatsCounter
import com.github.ghik.silencer.silent

import java.util.concurrent.{CompletableFuture, Executor}
import java.{lang, util}
import scala.collection.JavaConverters._
import scala.compat.java8.DurationConverters._
import scala.compat.java8.FunctionConverters._
Expand Down Expand Up @@ -258,6 +258,29 @@ case class Scaffeine[K, V](underlying: caffeine.cache.Caffeine[K, V]) {
})
)

/** Specifies a listener instance that caches should notify each time an entry is evicted.
*
* @param evictionListener a listener that caches should notify each time an entry is
* being automatically removed due to eviction
* @tparam K1 the key type of the listener
* @tparam V1 the value type of the listener
* @return this builder instance
* @throws java.lang.IllegalStateException if a removal listener was already set
*/
def evictionListener[K1 <: K, V1 <: V](
evictionListener: (K1, V1, caffeine.cache.RemovalCause) => Unit
): Scaffeine[K1, V1] =
Scaffeine(
underlying.evictionListener(new caffeine.cache.RemovalListener[K1, V1] {

override def onRemoval(
key: K1,
value: V1,
cause: caffeine.cache.RemovalCause
): Unit = evictionListener(key, value, cause)
})
)

/** Specifies a writer instance that caches should notify each time an entry is explicitly created
* or modified, or removed for any [[com.github.benmanes.caffeine.cache.RemovalCause]].
* <p>
Expand All @@ -270,6 +293,8 @@ case class Scaffeine[K, V](underlying: caffeine.cache.Caffeine[K, V]) {
* @return this builder instance
* @throws java.lang.IllegalStateException if a writer was already set or if the key strength is weak
*/
@deprecated("Scheduled for removal", "scaffeine 4.1.0")
@silent("deprecated")
def writer[K1 <: K, V1 <: V](
writer: caffeine.cache.CacheWriter[K1, V1]
): Scaffeine[K1, V1] =
Expand Down
@@ -1,17 +1,18 @@
package com.github.blemale.scaffeine

import java.util.concurrent.Executor

import com.github.benmanes.caffeine
import com.github.benmanes.caffeine.cache.Scheduler
import com.github.benmanes.caffeine.cache.stats.StatsCounter
import com.github.ghik.silencer.silent
import org.scalatest.PrivateMethodTester
import org.scalatest.matchers.should.Matchers
import org.scalatest.wordspec.AnyWordSpec

import scala.concurrent.duration._
import scala.concurrent.{ExecutionContext, Future}

@silent("deprecated")
class ScaffeineSpec extends AnyWordSpec with Matchers with PrivateMethodTester {

"Scaffeine" should {
Expand Down Expand Up @@ -197,7 +198,7 @@ class ScaffeineSpec extends AnyWordSpec with Matchers with PrivateMethodTester {

val getCacheWriter =
PrivateMethod[caffeine.cache.CacheWriter[Any, Any]]('getCacheWriter)
val cacheWriter = scaffeine.underlying invokePrivate getCacheWriter()
val cacheWriter = scaffeine.underlying invokePrivate getCacheWriter(false)

cacheWriter should be(writer)
}
Expand Down

0 comments on commit 0795898

Please sign in to comment.