@@ -10,6 +10,7 @@ import org.slf4j.LoggerFactory
1010import scala .concurrent .duration .Duration
1111import scala .concurrent .{ExecutionContext , Future }
1212import scalacache .caffeine .CaffeineCache
13+ import scalacache .modes .scalaFuture ._
1314
1415private [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