in pekko-sample-cluster-scala/src/main/scala/sample/cluster/stats/StatsWorker.scala [31:48]
private def withCache(ctx: ActorContext[Command],
cache: Map[String, Int]): Behavior[Command] =
Behaviors.receiveMessage {
case Process(word, replyTo) =>
ctx.log.info("Worker processing request [{}]", word)
cache.get(word) match {
case Some(length) =>
replyTo ! Processed(word, length)
Behaviors.same
case None =>
val length = word.length
val updatedCache = cache + (word -> length)
replyTo ! Processed(word, length)
withCache(ctx, updatedCache)
}
case EvictCache =>
withCache(ctx, Map.empty)
}