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.
- Alphabetic
- By Inheritance
- Cache
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Instance Constructors
- new Cache()
Abstract Value Members
-
abstract
def
cacheStats(implicit trace: Trace): UIO[CacheStats]
Returns statistics for this cache.
-
abstract
def
contains(key: Key)(implicit trace: Trace): UIO[Boolean]
Returns whether a value associated with the specified key exists in the cache.
-
abstract
def
entryStats(key: Key)(implicit trace: Trace): UIO[Option[EntryStats]]
Returns statistics for the specified entry.
-
abstract
def
get(key: Key)(implicit trace: Trace): IO[Error, Value]
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.
-
abstract
def
invalidate(key: Key)(implicit trace: Trace): UIO[Unit]
Invalidates the value associated with the specified key.
-
abstract
def
invalidateAll: UIO[Unit]
Invalidates all values in the cache.
-
abstract
def
refresh(key: Key): IO[Error, Unit]
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
getmethod is thatrefreshtriggers (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,refreshalways triggers the lookup function, disregarding the lastError. -
abstract
def
size(implicit trace: Trace): UIO[Int]
Returns the approximate number of values in the cache.
Concrete Value Members
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
def
toString(): String
- Definition Classes
- AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()