Class/Object

zio.cache

Cache

Related Docs: object Cache | package cache

Permalink

abstract class Cache[-Key, +Error, +Value] extends AnyRef

A Cache is defined in terms of a lookup function that, given a key of type Key, can either fail with an error of type Error or succeed with a value of type Value. Getting a value from the cache will either return the previous result of the lookup function if it is available or else compute a new result with the lookup function, put it in the cache, and return it.

A cache also has a specified capacity and time to live. When the cache is at capacity the least recently accessed values in the cache will be removed to make room for new values. Getting a value with a life older than the specified time to live will result in a new value being computed with the lookup function and returned when available.

The cache is safe for concurrent access. If multiple fibers attempt to get the same key the lookup function will only be computed once and the result will be returned to all fibers.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Cache
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Cache()

    Permalink

Abstract Value Members

  1. abstract def cacheStats(implicit trace: Trace): UIO[CacheStats]

    Permalink

    Returns statistics for this cache.

  2. abstract def contains(key: Key)(implicit trace: Trace): UIO[Boolean]

    Permalink

    Returns whether a value associated with the specified key exists in the cache.

  3. abstract def entryStats(key: Key)(implicit trace: Trace): UIO[Option[EntryStats]]

    Permalink

    Returns statistics for the specified entry.

  4. abstract def get(key: Key)(implicit trace: Trace): IO[Error, Value]

    Permalink

    Retrieves the value associated with the specified key if it exists.

    Retrieves the value associated with the specified key if it exists. Otherwise computes the value with the lookup function, puts it in the cache, and returns it.

  5. abstract def invalidate(key: Key)(implicit trace: Trace): UIO[Unit]

    Permalink

    Invalidates the value associated with the specified key.

  6. abstract def invalidateAll: UIO[Unit]

    Permalink

    Invalidates all values in the cache.

  7. abstract def refresh(key: Key): IO[Error, Unit]

    Permalink

    Computes the value associated with the specified key, with the lookup function, and puts it in the cache.

    Computes the value associated with the specified key, with the lookup function, and puts it in the cache. The difference between this and get method is that refresh triggers (re)computation of the value without invalidating it in the cache, so any request to the associated key can still be served while the value is being re-computed/retrieved by the lookup function. Additionally, refresh always triggers the lookup function, disregarding the last Error.

  8. abstract def size(implicit trace: Trace): UIO[Int]

    Permalink

    Returns the approximate number of values in the cache.

Concrete Value Members

  1. final def !=(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  5. def clone(): AnyRef

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  6. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  7. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  8. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  9. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  10. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  11. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  12. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  13. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  14. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  15. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  16. def toString(): String

    Permalink
    Definition Classes
    AnyRef → Any
  17. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  18. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  19. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Inherited from AnyRef

Inherited from Any

Ungrouped