object Cache
- Alphabetic
- By Inheritance
- Cache
- AnyRef
- Any
- Hide All
- Show All
- Public
- Protected
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(classOf[java.lang.CloneNotSupportedException]) @native() @IntrinsicCandidate()
- def empty[F[_], K, V](implicit arg0: Monad[F]): Cache[F, K, V]
Creates an always-empty implementation of cache.
Creates an always-empty implementation of cache.
The implementation *almost* always returns scala.None regardess the key. The notable exception are Cache#getOrUpdate, Cache#getOrUpdate1 and Cache#getOrUpdateOpt methods, which return the value passed to them to ensure the consistent behavior (i.e. it could be a suprise if someone calls Cache#getOrUpdateOpt with scala.Some and gets scala.None as a result).
It is meant to be used in tests, or as a stub in the code where cache should be disabled.
- final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
- def expiring[F[_], K, V](config: Config[F, K, V], partitions: Option[Int] = None)(implicit arg0: Temporal[F], arg1: Runtime[F], arg2: Parallel[F]): Resource[F, Cache[F, K, V]]
Creates a cache implementation, which is able remove the stale values.
Creates a cache implementation, which is able remove the stale values.
The underlying storage implementation is the same as in #loading[F[_],K,V](partitions:Option[Int])*, but the expiration routines are added on top of it.
Besides a value expiration leading to specific key being removed from the cache, the implementation is capable of _refreshing_ the values instead of removing them, which might be useful if the cache is used as a wrapper for setting or configuration service. The feature is possible to configure using
config
parameter.In adddition to context bounds used in #loading[F[_],K,V](partitions:Option[Int])*, this implementation also adds cats.effect.Clock (as part of cats.effect.Temporal), to have the ability to schedule cache clean up in a concurrent way.
Minimal usage example:
Cache.expiring[F, String, User]( config = ExpiringCache.Config(expireAfterRead = 1.minute), partitions = None, )
- F
Effect type. See #loading[F[_],K,V](partitions:Option[Int])* and Cache for more details.
- K
Key type. See Cache for more details.
- V
Value type. See Cache for more details.
- config
Cache configuration. See ExpiringCache.Config for more details on what parameters could be configured.
- partitions
Number of partitions to use, or scala.None in case number of partitions should be determined automatically using passed
Runtime
implementation.- returns
A new instance of a cache wrapped into cats.effect.Resource. Note, that Cache#clear method will be called on underlying cache when resource is released to make sure all resources stored in a cache are also released.
- def fromPartitions[F[_], K, V](partitions: Partitions[K, Cache[F, K, V]])(implicit arg0: MonadThrow[F], arg1: Parallel[F]): Cache[F, K, V]
Creates Cache interface to a set of precreated caches.
Creates Cache interface to a set of precreated caches.
This method is required to use common partitioning implementation for various caches and is not intended to be called directly. Cache partitioning itself allows splitting underlying cache into multiple partitions, so there is no contention on a single cats.effect.Ref when cache need to be updated.
It is only left public for sake of backwards compatibility.
Please consider using either #loading[F[_],K,V](partitions:Option[Int])* or #expiring instead.
Here is a short description of why some of the context bounds are required on
F[_]
:- cats.MonadError is required to throw an error in case partitioning function passed as part of Partitions does not return any values.
- cats.Parallel is required for an efficient Cache#foldMapPar implementation.
- final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native() @IntrinsicCandidate()
- final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
- def loading[F[_], K, V](partitions: Option[Int] = None)(implicit arg0: Concurrent[F], arg1: Parallel[F], arg2: Runtime[F]): Resource[F, Cache[F, K, V]]
Creates a cache implementation, which is able to load the missing values.
Creates a cache implementation, which is able to load the missing values.
To speed the operations, the cache may use several partitions each of whom may be accessed in parallel.
Note, that the values getting into this cache never expire, i.e. the cache will grow indefinetely unless Cache#remove is called. See #expiring for the implementation, which allows automatic expriation of the values.
Here is a short description of why some of the context bounds are required on
F[_]
:- cats.Parallel is required for an efficient Cache#foldMapPar implementation whenever cache partitioning is used. Cache partitioning itself allows splitting underlying cache into multiple partitions, so there is no contention on a single cats.effect.Ref when cache need to be updated.
Runtime
is used to determine optimal number of partitions based on CPU count if the value is not provided as a parameter.- cats.effect.Sync (which comes as part of cats.effect.Concurrent), allows internal structures using cats.effect.Ref and cats.effect.Deferred to be created.
- cats.effect.Concurrent, allows
release
parameter in Cache#put(key:K,value:V,release:Cache* and Cache#getOrUpdate1 methods to be called in background without waiting for release to be completed.
Minimal usage example:
Cache.loading[F, String, User](partitions = None)
- F
Effect type. See Cache for more details.
- K
Key type. See Cache for more details.
- V
Value type. See Cache for more details.
- partitions
Number of partitions to use, or scala.None in case number of partitions should be determined automatically using passed
Runtime
implementation.- returns
A new instance of a cache wrapped into cats.effect.Resource. Note, that Cache#clear method will be called on underlying cache when resource is released to make sure all resources stored in a cache are also released.
- def loading[F[_], K, V](partitions: Int)(implicit arg0: Concurrent[F], arg1: Parallel[F], arg2: Runtime[F]): Resource[F, Cache[F, K, V]]
Creates a cache implementation, which is able to load the missing values.
Creates a cache implementation, which is able to load the missing values.
Same as #loading[F[_],K,V](partitions:Option[Int])*, but without the need to use
Option
.Minimal usage example:
Cache.loading[F, String, User](partitions = 8)
- returns
A new instance of a cache wrapped into cats.effect.Resource. Note, that Cache#clear method will be called on underlying cache when resource is released to make sure all resources stored in a cache are also released.
- def loading[F[_], K, V](implicit arg0: Concurrent[F], arg1: Parallel[F], arg2: Runtime[F]): Resource[F, Cache[F, K, V]]
Creates a cache implementation, which is able to load the missing values.
Creates a cache implementation, which is able to load the missing values.
Same as #loading[F[_],K,V](partitions:Int)*, but with number of paritions determined automatically using passed
Runtime
implementation.Minimal usage example:
Cache.loading[F, String, User]
- returns
A new instance of a cache wrapped into cats.effect.Resource. Note, that Cache#clear method will be called on underlying cache when resource is released to make sure all resources stored in a cache are also released.
- final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
- final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native() @IntrinsicCandidate()
- final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
- def toString(): String
- Definition Classes
- AnyRef → Any
- final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
- final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
- final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])