sup has a Scalacache module:

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

Imports:

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

What’s included

cached

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._, cats.data._, scala.concurrent.duration._, scalacache._, sup.mods._, sup.data._
// import cats._
// import cats.effect._
// import cats.data._
// import scala.concurrent.duration._
// import scalacache._
// import sup.mods._
// import sup.data._

//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$]sup.data.Tagged[String,β$0$]]

def q1 = queueCheck("foo").through(cached("queue-foo", Some(10.seconds)))
// q1: sup.HealthCheck[cats.effect.IO,[H]sup.data.Tagged[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, ?]] =
  HealthReporter.fromChecks(
    queueCheck("foo").through(cached("queue-foo", Some(10.seconds))),
    queueCheck("bar")
  ).through(cached("report", Some(5.seconds)))
// reporter: sup.HealthReporter[cats.effect.IO,cats.data.NonEmptyList,[β$0$]sup.data.Tagged[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.