Is this a proper way to cache side effects (occurring on job.tryLoad)?

case class DFStorage(private var cache: Map[String, DataFrame] = Map()) {
  def tryLoad(job: Job): Kleisli[IO, MakeContext, \/[List[String], Unit]] = {
    if(!cache.contains(job.id)) {
      job.tryLoad.map(_.map(df => add(job, df)))
    } else {
  def add(job: Job, df: DataFrame): IO[Unit] = {
    IO(cache += (job.id -> df))
  def toMap = IO(cache)
  • \$\begingroup\$ Is the IO something internal? I can't find any documentation for it. \$\endgroup\$
    – gardenhead
    Commented Jan 4, 2016 at 22:27
  • \$\begingroup\$ @gardenhead scalaz.effect.IO \$\endgroup\$ Commented Jan 5, 2016 at 3:24

1 Answer 1


Looks good to me.

Although, having cache as a simple Map might lay claim to more memory that you like. Associating an LRU with it would allow each addition to evict an ancient job's cached dataframe.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.