Skip to main content
Version: 2.x

Entry Statistics

ZIO Cache also tracks statistics for each entry, such as when the entry was loaded into the cache. You can access the statistics for a specified entry using the entryStats operator on Cache, passing the key of the entry.

The EntryStats type is a case class with one field, loaded:

import zio._
import zio.cache.{Cache, EntryStats}

def loadedAt(cache: Cache[String, Nothing, Int], key: String): UIO[Option[java.time.Instant]] =
cache.entryStats(key).map(_.map((stats: EntryStats) => stats.loaded))

loaded is the instant when the lookup for the entry completed. entryStats returns None when the cache holds no value for that key, including while the first lookup for the key is still running. An expired value that has not been removed yet still returns its statistics.

More entry statistics will be added over time.

ZIO Chat

Hi there! ๐Ÿ‘‹ I'm ZIO Chat, your friendly neighborhood ZIO expert. I'm here to help you navigate the world of ZIO. Whether you're a seasoned pro or just starting out, fire away with your ZIO questions. I will hit you back with the best insights I've got. Let's dive into the world of ZIO together!