Skip to content

Commit 6d2ff1a

Browse files
author
Sheng Ran
committed
Update scalacache
- Bump scalacache to 0.22.0
1 parent 7d31ad2 commit 6d2ff1a

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,9 @@ lazy val root = (project in file("."))
9595
libraryDependencies ++= Seq(
9696
"org.slf4j" % "slf4j-api" % "1.7.25",
9797
"org.json4s" %% "json4s-native" % "3.4.2",
98-
"com.criteo.lolhttp" %% "lolhttp" % "0.9.2",
99-
"com.github.cb372" %% "scalacache-core" % "0.9.4",
100-
"com.github.cb372" %% "scalacache-caffeine" % "0.9.4",
98+
"com.criteo.lolhttp" %% "lolhttp" % "0.9.3",
99+
"com.github.cb372" %% "scalacache-core" % "0.22.0",
100+
"com.github.cb372" %% "scalacache-caffeine" % "0.22.0",
101101
"com.chuusai" %% "shapeless" % "2.3.3",
102102
"org.typelevel" %% "cats-core" % "1.0.1",
103103
"org.typelevel" %% "cats-effect" % "0.8",

src/main/scala/com/criteo/slab/app/StateService.scala

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory
1010
import scala.concurrent.duration.Duration
1111
import scala.concurrent.{ExecutionContext, Future}
1212
import scalacache.caffeine.CaffeineCache
13+
import scalacache.modes.scalaFuture._
1314

1415
private[slab] class StateService(
1516
val executors: Seq[Executor[_]],
@@ -24,7 +25,9 @@ private[slab] class StateService(
2425

2526
private val logger = LoggerFactory.getLogger(this.getClass)
2627

27-
private implicit val scalaCache = ScalaCache(CaffeineCache())
28+
private implicit lazy val boardCache = CaffeineCache[BoardView]
29+
private implicit lazy val historyCache = CaffeineCache[Map[Long, String]]
30+
private implicit lazy val sloCache = CaffeineCache[Map[Long, Double]]
2831

2932
private lazy val scheduler = Executors.newSingleThreadScheduledExecutor()
3033

@@ -33,7 +36,7 @@ private[slab] class StateService(
3336
}
3437

3538
// Current board view
36-
def current(board: String): Future[BoardView] = get[BoardView, NoSerialization](board) flatMap {
39+
def current(board: String): Future[BoardView] = get[Future, BoardView](board).flatMap {
3740
case Some(boardView) => Future.successful(boardView)
3841
case None =>
3942
if (executors.exists(_.board.title == board))
@@ -45,11 +48,11 @@ private[slab] class StateService(
4548
// All available board views
4649
def all(): Future[Seq[BoardView]] =
4750
Future
48-
.sequence(executors.map { e => get[BoardView, NoSerialization](e.board.title) })
51+
.sequence(executors.map { e => get[Future, BoardView](e.board.title) })
4952
.map(_.collect { case Some(boardView) => boardView })
5053

5154
// History of last 24 hours
52-
def history(board: String): Future[Map[Long, String]] = memoize(Duration.create(10, TimeUnit.MINUTES)) {
55+
def history(board: String): Future[Map[Long, String]] = memoizeF[Future, Map[Long, String]](Some(Duration.create(10, TimeUnit.MINUTES))) {
5356
logger.info(s"Updating history of $board")
5457
val now = Instant.now
5558
executors.find(_.board.title == board)
@@ -75,9 +78,10 @@ private[slab] class StateService(
7578
Duration.create(12, TimeUnit.HOURS).plus(Duration.create((Math.random() * 30).toInt, TimeUnit.MINUTES))
7679

7780
//cache only full months
78-
def boardMonthlySloInner(board: String, from: ZonedDateTime, until: ZonedDateTime): Future[Map[Long, Double]] = memoize(getSloCacheDuration(from)) {
79-
executor.fetchHourlySlo(from.toInstant, until.toInstant).map(_.toMap)
80-
}
81+
def boardMonthlySloInner(board: String, from: ZonedDateTime, until: ZonedDateTime): Future[Map[Long, Double]] =
82+
memoizeF(Some(getSloCacheDuration(from))) {
83+
executor.fetchHourlySlo(from.toInstant, until.toInstant).map(_.toMap)
84+
}
8185

8286
val from = now.minus(statsDays, ChronoUnit.DAYS)
8387
val until = now

0 commit comments

Comments
 (0)