Skip to content

Commit

Permalink
Merge 4f8edc0 into 002fc69
Browse files Browse the repository at this point in the history
  • Loading branch information
blemale committed Jun 5, 2021
2 parents 002fc69 + 4f8edc0 commit a519c90
Show file tree
Hide file tree
Showing 10 changed files with 23 additions and 148 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
@@ -1,12 +1,14 @@
name: CI
on: [push]
on: [push,pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: coursier/cache-action@v6
- uses: olafurpg/setup-scala@v11
with:
java-version: zulu@1.11
- run: sbt clean scalafmtSbtCheck scalafmtCheck coverage +test +doc
- run: sbt coverageReport coveralls
env:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Expand Up @@ -11,6 +11,8 @@ jobs:
with:
fetch-depth: 0
- uses: olafurpg/setup-scala@v11
with:
java-version: zulu@1.11
- run: sbt ci-release
env:
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
Expand Down
23 changes: 2 additions & 21 deletions build.sbt
Expand Up @@ -19,8 +19,8 @@ inThisBuild(
)
)

scalaVersion := "2.11.12"
crossScalaVersions := Seq("2.11.12", "2.12.14", "2.13.6")
scalaVersion := "2.12.14"
crossScalaVersions := Seq("2.12.14", "2.13.6")

libraryDependencies ++=
Seq(
Expand All @@ -41,25 +41,6 @@ scalacOptions ++= Seq("-target:jvm-1.8")

scalacOptions ++=
(CrossVersion.partialVersion(scalaVersion.value) match {
case Some((2, 11)) =>
Seq(
"-deprecation",
"-encoding",
"UTF-8",
"-feature",
"-language:existentials",
"-language:higherKinds",
"-language:implicitConversions",
"-unchecked",
"-Xfatal-warnings",
"-Xlint",
"-Yno-adapted-args",
"-Ywarn-dead-code",
"-Ywarn-numeric-widen",
"-Ywarn-value-discard",
"-Xfuture",
"-Ywarn-unused-import"
)
case Some((2, 12)) =>
Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
Expand Down
2 changes: 1 addition & 1 deletion project/CaffeineVersion.scala
@@ -1,5 +1,5 @@
object CaffeineVersion {

val value: String = "2.9.1"
val value: String = "3.0.2"

}
2 changes: 2 additions & 0 deletions project/plugins.sbt
Expand Up @@ -9,3 +9,5 @@ addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.5.3")
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")

addSbtPlugin("com.geirsson" % "sbt-ci-release" % "1.5.7")

addSbtPlugin("com.thoughtworks.sbt-api-mappings" % "sbt-api-mappings" % "3.0.0")
72 changes: 0 additions & 72 deletions scaladoc.sbt

This file was deleted.

Expand Up @@ -30,7 +30,7 @@ public CompletableFuture<V> asyncLoad(@Nonnull K key, @Nonnull Executor executor

@Nonnull
@Override
public CompletableFuture<V> asyncReload(@Nonnull K key, @Nonnull V oldValue, @Nonnull Executor executor) {
public CompletableFuture<? extends V> asyncReload(@Nonnull K key, @Nonnull V oldValue, @Nonnull Executor executor) throws Exception {
if (reloadLoader.isEmpty()) {
return AsyncCacheLoader.super.asyncReload(key, oldValue, executor);
} else {
Expand Down
Expand Up @@ -3,6 +3,8 @@ package com.github.blemale.scaffeine
import com.github.benmanes.caffeine.cache.{LoadingCache => CaffeineLoadingCache}

import scala.collection.JavaConverters._
import scala.compat.java8.FutureConverters._
import scala.concurrent.Future

object LoadingCache {

Expand Down Expand Up @@ -50,8 +52,8 @@ class LoadingCache[K, V](override val underlying: CaffeineLoadingCache[K, V])
*
* @param key key with which a value may be associated
*/
def refresh(key: K): Unit =
underlying.refresh(key)
def refresh(key: K): Future[V] =
underlying.refresh(key).toScala

override def toString = s"LoadingCache($underlying)"
}
35 changes: 7 additions & 28 deletions src/main/scala/com/github/blemale/scaffeine/Scaffeine.scala
Expand Up @@ -3,10 +3,9 @@ package com.github.blemale.scaffeine
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
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 @@ -113,7 +112,6 @@ case class Scaffeine[K, V](underlying: caffeine.cache.Caffeine[K, V]) {
/** Specifies that each key (not value) stored in the cache should be wrapped in a
* [[java.lang.ref.WeakReference]] (by default, strong references are used).
* <p>
* This feature cannot be used in conjunction with [[Scaffeine.writer]].
*
* @return this builder instance
* @throws java.lang.IllegalStateException if the key strength was already set or the writer was set
Expand Down Expand Up @@ -281,25 +279,6 @@ case class Scaffeine[K, V](underlying: caffeine.cache.Caffeine[K, V]) {
})
)

/** 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>
* This feature cannot be used in conjunction with [[Scaffeine.weakKeys]] or [[Scaffeine.buildAsync[K1<:K,V1<:V]()*]].
*
* @param writer a writer instance that caches should notify each time an entry is explicitly
* created or modified, or removed for any reason
* @tparam K1 the key type of the writer
* @tparam V1 the value type of the writer
* @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] =
Scaffeine(underlying.writer(writer))

/** Enables the accumulation of [[com.github.benmanes.caffeine.cache.stats.CacheStats]]
* during the operation of the cache.
*
Expand Down Expand Up @@ -439,34 +418,34 @@ case class Scaffeine[K, V](underlying: caffeine.cache.Caffeine[K, V]) {

private[this] def toCacheLoader[K1 <: K, V1 <: V](
loader: K1 => V1,
allLoader: Option[Iterable[K1] => Map[K1, V1]],
allLoader: Option[Set[K1] => Map[K1, V1]],
reloadLoader: Option[(K1, V1) => V1]
): caffeine.cache.CacheLoader[K1, V1] =
allLoader match {
case Some(l) =>
new CacheLoaderAdapter[K1, V1](loader, reloadLoader) {

override def loadAll(keys: lang.Iterable[_ <: K1]): util.Map[K1, V1] =
l(keys.asScala).asJava
override def loadAll(keys: util.Set[_ <: K1]): util.Map[K1, V1] =
l(keys.asScala.toSet).asJava
}
case None =>
new CacheLoaderAdapter[K1, V1](loader, reloadLoader)
}

private[this] def toAsyncCacheLoader[K1 <: K, V1 <: V](
loader: K1 => Future[V1],
allLoader: Option[Iterable[K1] => Future[Map[K1, V1]]],
allLoader: Option[Set[K1] => Future[Map[K1, V1]]],
reloadLoader: Option[(K1, V1) => Future[V1]]
): caffeine.cache.AsyncCacheLoader[K1, V1] =
allLoader match {
case Some(l) =>
new AsyncCacheLoaderAdapter[K1, V1](loader, reloadLoader) {

override def asyncLoadAll(
keys: lang.Iterable[_ <: K1],
keys: util.Set[_ <: K1],
executor: Executor
): CompletableFuture[util.Map[K1, V1]] =
l(keys.asScala)
l(keys.asScala.toSet)
.map(_.asJava)(DirectExecutionContext)
.toJava
.toCompletableFuture
Expand Down
23 changes: 1 addition & 22 deletions src/test/scala/com/github/blemale/scaffeine/ScaffeineSpec.scala
@@ -1,18 +1,16 @@
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 java.util.concurrent.Executor
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 @@ -184,25 +182,6 @@ class ScaffeineSpec extends AnyWordSpec with Matchers with PrivateMethodTester {
removalListener shouldNot be(null)
}

"set cache writer" in {
val writer = new caffeine.cache.CacheWriter[Any, Any] {
override def write(key: Any, value: Any): Unit = println("write")
override def delete(
key: Any,
value: Any,
cause: caffeine.cache.RemovalCause
): Unit = println("delete")
}

val scaffeine = Scaffeine().writer(writer)

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

cacheWriter should be(writer)
}

"set record stats" in {
val scaffeine = Scaffeine().recordStats()

Expand Down

0 comments on commit a519c90

Please sign in to comment.