Package arez.component.internal
Class MemoizeCache<T>
java.lang.Object
arez.component.internal.MemoizeCache<T>
- All Implemented Interfaces:
Disposable
The class responsible for caching
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Functional interface for calculating memoizable value. -
Constructor Summary
ConstructorDescriptionMemoizeCache
(ArezContext context, Component component, String name, MemoizeCache.Function<T> function, int argCount) Create the Memoize method cache.MemoizeCache
(ArezContext context, Component component, String name, MemoizeCache.Function<T> function, int argCount, int flags) Create the Memoize method cache. -
Method Summary
Modifier and TypeMethodDescriptionvoid
dispose()
Dispose the element.Return the result of the memoized function, calculating if necessary.getComputableValue
(Object... args) Retrieve the computable value for specified parameters, creating it if necessary.boolean
Return true if dispose() has been called on object.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface arez.Disposable
isNotDisposed
-
Constructor Details
-
MemoizeCache
public MemoizeCache(@Nullable ArezContext context, @Nullable Component component, @Nullable String name, @Nonnull MemoizeCache.Function<T> function, int argCount) Create the Memoize method cache.- Parameters:
context
- the context in which to create ComputableValue instances.component
- the associated native component if any. This should only be set ifArez.areNativeComponentsEnabled()
returns true.name
- a human consumable prefix for computable values.function
- the memoized function.argCount
- the number of arguments expected to be passed to memoized function.
-
MemoizeCache
public MemoizeCache(@Nullable ArezContext context, @Nullable Component component, @Nullable String name, @Nonnull MemoizeCache.Function<T> function, int argCount, int flags) Create the Memoize method cache.- Parameters:
context
- the context in which to create ComputableValue instances.component
- the associated native component if any. This should only be set ifArez.areNativeComponentsEnabled()
returns true.name
- a human consumable prefix for computable values.function
- the memoized function.argCount
- the number of arguments expected to be passed to memoized function.flags
- the flags that are used when creating ComputableValue instances. The only flags supported are flags defined inComputableValue.Flags
except forComputableValue.Flags.KEEPALIVE
,ComputableValue.Flags.RUN_NOW
andComputableValue.Flags.RUN_LATER
.
-
-
Method Details
-
get
Return the result of the memoized function, calculating if necessary.- Parameters:
args
- the arguments passed to the memoized function.- Returns:
- the result of the memoized function.
-
isDisposed
Description copied from interface:Disposable
Return true if dispose() has been called on object.- Specified by:
isDisposed
in interfaceDisposable
- Returns:
- true if dispose has been called.
-
dispose
Description copied from interface:Disposable
Dispose the element. SeeDisposable
for a description of the implications.- Specified by:
dispose
in interfaceDisposable
-
getComputableValue
Retrieve the computable value for specified parameters, creating it if necessary.- Parameters:
args
- the arguments passed to the memoized function.- Returns:
- the computable value instance for the specified args.
-