sup has a Scalacache module:

libraryDependencies += "com.kubukoz" %% "sup-scalacache" % "0.7.0-M2"


import sup._, sup.modules.scalacache._

What’s included


You can make a healthcheck cached by transforming it with the cached function (which is a pretty thin wrapper over cache.cachingForMemoizeF(key)(ttl), so you can just use that).

Let’s grab a bunch of imports and define our Scalacache config:

import cats._, cats.effect._,, scala.concurrent.duration._, scalacache._, sup.mods._,
// import cats._
// import cats.effect._
// import
// import scala.concurrent.duration._
// import scalacache._
// import sup.mods._
// import

//you'll probably want to implement these
implicit def cache[H[_]]: Cache[HealthResult[H]] = ???
// cache: [H[_]]=> scalacache.Cache[sup.HealthResult[H]]

implicit def mode[F[_]]: Mode[F] = ???
// mode: [F[_]]=> scalacache.Mode[F]

Now, the health check:

def queueCheck(queueName: String): HealthCheck[IO, Tagged[String, ?]] =
  HealthCheck.const[IO, Id](Health.Healthy).through(tagWith(queueName))
// queueCheck: (queueName: String)sup.HealthCheck[cats.effect.IO,[β$0$][String,β$0$]]

def q1 = queueCheck("foo").through(cached("queue-foo", Some(10.seconds)))
// q1: sup.HealthCheck[cats.effect.IO,[H][String,H]]

Because a HealthReporter is just a special case of HealthCheck, the same modifier works for reporters:

def reporter: HealthReporter[IO, NonEmptyList, Tagged[String, ?]] =
    queueCheck("foo").through(cached("queue-foo", Some(10.seconds))),
  ).through(cached("report", Some(5.seconds)))
// reporter: sup.HealthReporter[cats.effect.IO,,[β$0$][String,β$0$]]

The above will be a HealthReporter that’ll cache the whole system’s health for 5 seconds, also caching the first queue’s health for 10 seconds.