Last active
August 29, 2015 14:06
Revisions
-
kareblak revised this gist
Sep 4, 2014 . 1 changed file with 11 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,5 +22,15 @@ purge() } ... def get(key: K, orElse: FV): Option[V] = { get(key).orElse { Option(orElse()).map { value => val element = new Element(key, value) cache.put(element) value } } } } -
kareblak created this gist
Sep 4, 2014 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,26 @@ case class GetOrElseCachedValue[K, V](key: K, orElse: () => V) case class GetCachedValue[K, V](key: K) case class PutCachedValue[K, V](key: K, value: V) case class ReturnCachedValue[V](value: Option[V]) case class RemoveCachedValue[K](key: K) case object PurgeCachedValues class CacheActor[K, V] private[cache](cache: Cache) extends Actor with ActorLogging with StatsD { type FV = (() => V) def receive = { case GetOrElseCachedValue(key: K, orElse: FV) => sender ! ReturnCachedValue(get(key, orElse)) case GetCachedValue(key: K) => sender ! ReturnCachedValue(get(key)) case PutCachedValue(key: K, value: FV) => put(key, value) case RemoveCachedValue(key: K) => remove(key) case PurgeCachedValues => purge() } } }