Packages

final case class Cached[+T](value: T) extends AnyVal with Product with Serializable

Wraps a cached implicit T.

Looking for an implicit Cached[T] first triggers a look for an implicit T, caches the resulting tree, and returns it immediately and in subsequent look ups for an implicit Cached[T]. Thus, subsequent look ups do not trigger looking for an implicit T, only returning the instance kept in cache.

Beware that if the contexts in which two subsequent look ups are different, so that looking for a T in each of them doesn't return the same result, this change would be ignored by caching. Looking for a Cached[T] in the first context would put the implicit T of this context in cache, and then looking for a Cached[T] in the second context would return the former instance from the first context. E.g.

trait TC[T] {
  def msg: String
}

object First {
  implicit val tc: TC[Int] = new TC[Int] {
    val msg = "first"
  }

  def print() = println(implicitly[TC[Int]].msg)
  def printCached() = println(cached[TC[Int]].msg)
}

object Second {
  implicit val tc: TC[Int] = new TC[Int] {
    val msg = "second"
  }

  def print() = println(implicitly[TC[Int]].msg)
  def printCached() = println(cached[TC[Int]].msg)
}

First.print()
Second.print()
First.printCached()
Second.printCached()

would print "first" then "second" (non cached TC[Int] instances), then "first" twice (first instance, returned the second time too through the cache).

Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Cached
  2. Serializable
  3. Serializable
  4. Product
  5. Equals
  6. AnyVal
  7. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Cached(value: T)

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    Any
  2. final def ##(): Int
    Definition Classes
    Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    Any
  4. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  5. def getClass(): Class[_ <: AnyVal]
    Definition Classes
    AnyVal → Any
  6. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  7. val value: T

Inherited from Serializable

Inherited from Serializable

Inherited from Product

Inherited from Equals

Inherited from AnyVal

Inherited from Any

Ungrouped