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.
- Alphabetic
- By Inheritance
- memoization
- AnyRef
- Any
- Hide All
- Show All
- Public
- All
Type Members
- class Macros extends AnyRef
-
case class
MemoizationConfig(toStringConverter: MethodCallToStringConverter = ...) extends Product with Serializable
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
-
trait
MethodCallToStringConverter extends AnyRef
Converts information about a method call to a String for use in a cache key
-
final
class
cacheKeyExclude extends Annotation with StaticAnnotation
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
-
macro
def
memoize[F[_], V](ttl: Option[Duration])(f: ⇒ V)(implicit cache: Cache[V], mode: Mode[F], flags: Flags): F[V]
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.
If a TTL is given, the result is stored in the cache with that 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.
- F
The type of container in which the result will be wrapped. This is decided by the mode.
- V
The type of the value to be cached
- ttl
Time-To-Live
- f
A function that computes some result. This result is the value that will be cached.
- cache
The cache
- mode
The operation mode, which decides the type of container in which to wrap the result
- flags
Flags used to conditionally alter the behaviour of ScalaCache
- returns
A result, either retrieved from the cache or calculated by executing the function
f
-
macro
def
memoizeF[F[_], V](ttl: Option[Duration])(f: ⇒ F[V])(implicit cache: Cache[V], mode: Mode[F], flags: Flags): F[V]
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.
If a TTL is given, the result is stored in the cache with that 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.
- F
The type of container in which the result will be wrapped. This is decided by the mode.
- V
The type of the value to be cached
- ttl
Time-To-Live
- f
A function that computes some result wrapped in an F. This result is the value that will be cached.
- cache
The cache
- mode
The operation mode, which decides the type of container in which to wrap the result
- flags
Flags used to conditionally alter the behaviour of ScalaCache
- returns
A result, either retrieved from the cache or calculated by executing the function
f
-
macro
def
memoizeSync[V](ttl: Option[Duration])(f: ⇒ V)(implicit cache: Cache[V], mode: Mode[Id], flags: Flags): V
A version of memoize that is specialised to Id.
A version of memoize that is specialised to Id. This is provided for convenience because type inference doesn't work properly for Id, and writing
memoize[Id, Foo]
is a bit rubbish.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.
If a TTL is given, the result is stored in the cache with that 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.
- V
The type of the value to be cached
- ttl
Time-To-Live
- f
A function that computes some result. This result is the value that will be cached.
- cache
The cache
- flags
Flags used to conditionally alter the behaviour of ScalaCache
- returns
A result, either retrieved from the cache or calculated by executing the function
f
- object MethodCallToStringConverter