Skip to content

Instantly share code, notes, and snippets.

@missingfaktor
Created October 18, 2015 13:31
Show Gist options
  • Select an option

  • Save missingfaktor/4048f7f12b87313fb05c to your computer and use it in GitHub Desktop.

Select an option

Save missingfaktor/4048f7f12b87313fb05c to your computer and use it in GitHub Desktop.
trait Cache[R[_], W[_], Eff[_]] {
def save[V](key: String, value: V)(implicit writes: W[V]): Eff[Unit]
def retrieve[V](key: String)(implicit reads: R[V]): Eff[Option[V]]
}
// In-memory cache. Potentially backed by a Map[String, Any].
// Needs no reads or writes.
class InMemoryCache extends Cache[Tautology1, Tautology1, Id] {
def save[V](key: String, value: V)(implicit writes: Tautology1[V]): Unit = ???
def retrieve[V](key: String)(implicit reads: Tautology1[V]): Option[V] = ???
}
class Tautology1[+A] private()
object Tautology {
implicit val tautology1 = new Tautology[Nothing]
}
// Zookeeper-based cache
class ZkCache extends Cache[ZkReads, ZkWrites, Future] {
def save[V](key: String, value: V)(implicit writes: ZkWrites[V]): Future[Unit] = ???
def retrieve[V](key: String)(implicit reads: ZkReads[V]): Future[Option[V]] = ???
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment