Package

scalacache

memoization

Permalink

package memoization

Utilities for memoizing the results of method calls in a cache. The cache key is generated from the method arguments using a macro, so that you don't have to bother passing them manually.

Linear Supertypes
AnyRef, Any
Ordering
  1. Alphabetic
  2. By inheritance
Inherited
  1. memoization
  2. AnyRef
  3. Any
  1. Hide All
  2. Show all
Visibility
  1. Public
  2. All

Type Members

  1. class Macros extends AnyRef

    Permalink
  2. case class MemoizationConfig(toStringConverter: MethodCallToStringConverter = ...) extends Product with Serializable

    Permalink

    Configuration related to the behaviour of the scalacache.memoization.memoize{Sync} methods.

    Configuration related to the behaviour of the scalacache.memoization.memoize{Sync} methods.

    toStringConverter

    converter for generating a String cache key from information about a method call

  3. trait MethodCallToStringConverter extends AnyRef

    Permalink

    Converts information about a method call to a String for use in a cache key

  4. final class cacheKeyExclude extends Annotation with StaticAnnotation

    Permalink

    Add this annotation to method or class constructor parameters in order to exclude them from auto-generated cache keys.

    Add this annotation to method or class constructor parameters in order to exclude them from auto-generated cache keys.

    e.g.

    def foo(a: Int, @cacheKeyExclude b: String, c: String): Int = memoize { ... }

    will not include the value of the b parameter in its cache keys.

Value Members

  1. object MethodCallToStringConverter

    Permalink
  2. macro def memoize[A](optionalTtl: Option[Duration])(f: ⇒ Future[A])(implicit scalaCache: ScalaCache, flags: Flags, ec: ExecutionContext): Future[A]

    Permalink

    Perform the given operation and memoize its result to a cache before returning it.

    Perform the given operation and memoize its result to a cache before returning it. If the result is already in the cache, return it without performing the operation.

    All of the above happens asynchronously, so a Future is returned immediately. Specifically: - when the cache lookup completes, if it is a miss, the function execution is started. - at some point after the function completes, the result is written asynchronously to the cache. - the Future returned from this method does not wait for the cache write before completing.

    The result is stored in the cache with the given TTL. It will be evicted when the TTL is up.

    Note that if the result is currently in the cache, changing the TTL has no effect. TTL is only set once, when the result is added to the cache.

    A

    type of the value to be cached

    optionalTtl

    Optional Time to Live. If defined, how long the result should be stored in the cache.

    f

    function that returns some result. This result is the value that will be cached.

    scalaCache

    cache configuration

    flags

    flags to customize ScalaCache behaviour

    returns

    the result, either retrieved from the cache or calculated by executing the function f

  3. macro def memoize[A](ttl: Duration)(f: ⇒ Future[A])(implicit scalaCache: ScalaCache, flags: Flags, ec: ExecutionContext): Future[A]

    Permalink

    Perform the given operation and memoize its result to a cache before returning it.

    Perform the given operation and memoize its result to a cache before returning it. If the result is already in the cache, return it without performing the operation.

    All of the above happens asynchronously, so a Future is returned immediately. Specifically: - when the cache lookup completes, if it is a miss, the function execution is started. - at some point after the function completes, the result is written asynchronously to the cache. - the Future returned from this method does not wait for the cache write before completing.

    The result is stored in the cache with the given TTL. It will be evicted when the TTL is up.

    Note that if the result is currently in the cache, changing the TTL has no effect. TTL is only set once, when the result is added to the cache.

    A

    type of the value to be cached

    ttl

    Time To Live. How long the result should be stored in the cache.

    f

    function that asynchronously returns some result. This result is the value that will be cached.

    scalaCache

    cache configuration

    flags

    flags to customize ScalaCache behaviour

    ec

    An ExecutionContext in which to execute operations on Futures

    returns

    a Future of the result, either retrieved from the cache or calculated by executing the function f

  4. macro def memoize[A](f: ⇒ Future[A])(implicit scalaCache: ScalaCache, flags: Flags, ec: ExecutionContext): Future[A]

    Permalink

    Perform the given operation and memoize its result to a cache before returning it.

    Perform the given operation and memoize its result to a cache before returning it. If the result is already in the cache, return it without performing the operation.

    All of the above happens asynchronously, so a Future is returned immediately. Specifically: - when the cache lookup completes, if it is a miss, the function execution is started. - at some point after the function completes, the result is written asynchronously to the cache. - the Future returned from this method does not wait for the cache write before completing.

    The result is stored in the cache without a TTL, so it will remain until it is naturally evicted.

    A

    type of the value to be cached

    f

    function that asynchronously returns some result. This result is the value that will be cached.

    scalaCache

    cache configuration

    flags

    flags to customize ScalaCache behaviour

    ec

    An ExecutionContext in which to execute operations on Futures

    returns

    a Future of the result, either retrieved from the cache or calculated by executing the function f

  5. macro def memoizeSync[A](optionalTtl: Option[Duration])(f: ⇒ A)(implicit scalaCache: ScalaCache, flags: Flags): A

    Permalink

    Perform the given operation and memoize its result to a cache before returning it.

    Perform the given operation and memoize its result to a cache before returning it. If the result is already in the cache, return it without performing the operation.

    The result is stored in the cache with the given TTL. It will be evicted when the TTL is up.

    Note that if the result is currently in the cache, changing the TTL has no effect. TTL is only set once, when the result is added to the cache.

    Warning: may block indefinitely!

    A

    type of the value to be cached

    optionalTtl

    Optional Time to Live. If defined, how long the result should be stored in the cache.

    f

    function that returns some result. This result is the value that will be cached.

    scalaCache

    cache configuration

    flags

    flags to customize ScalaCache behaviour

    returns

    the result, either retrieved from the cache or calculated by executing the function f

  6. macro def memoizeSync[A](ttl: Duration)(f: ⇒ A)(implicit scalaCache: ScalaCache, flags: Flags): A

    Permalink

    Perform the given operation and memoize its result to a cache before returning it.

    Perform the given operation and memoize its result to a cache before returning it. If the result is already in the cache, return it without performing the operation.

    The result is stored in the cache with the given TTL. It will be evicted when the TTL is up.

    Note that if the result is currently in the cache, changing the TTL has no effect. TTL is only set once, when the result is added to the cache.

    Warning: may block indefinitely!

    A

    type of the value to be cached

    ttl

    Time To Live. How long the result should be stored in the cache.

    f

    function that returns some result. This result is the value that will be cached.

    scalaCache

    cache configuration

    flags

    flags to customize ScalaCache behaviour

    returns

    the result, either retrieved from the cache or calculated by executing the function f

  7. macro def memoizeSync[A](f: ⇒ A)(implicit scalaCache: ScalaCache, flags: Flags): A

    Permalink

    Perform the given operation and memoize its result to a cache before returning it.

    Perform the given operation and memoize its result to a cache before returning it. If the result is already in the cache, return it without performing the operation.

    The result is stored in the cache without a TTL, so it will remain until it is naturally evicted.

    Warning: may block indefinitely!

    A

    type of the value to be cached

    f

    function that returns some result. This result is the value that will be cached.

    scalaCache

    cache configuration

    flags

    flags to customize ScalaCache behaviour

    returns

    the result, either retrieved from the cache or calculated by executing the function f

Inherited from AnyRef

Inherited from Any

Ungrouped