@PublicApi public enum AttributeCachingStrategy extends Enum<AttributeCachingStrategy>
Defines how the values provided by an attribute loader are cached.
Most attribute loaders should not need to define the caching strategy, as the system will try to pick the optimal strategy. By default, attributes engine tries to cache most of the values.
AttributeLoader.getCachingStrategy()
Enum Constant and Description |
---|
MAY
The value may be cached.
|
MUST_NOT
The value must not be cached.
|
SHOULD
The value should be cached to avoid excessive recalculation.
|
SHOULD_NOT
The value should not be cached, although it potentially could be done.
|
Modifier and Type | Method and Description |
---|---|
static AttributeCachingStrategy |
guessCachingStrategy(AttributeSpec<?> spec)
Guessing if the value is cacheable, based on the value format.
|
static AttributeCachingStrategy |
valueOf(String name)
Returns the enum constant of this type with the specified name.
|
static AttributeCachingStrategy[] |
values()
Returns an array containing the constants of this enum type, in
the order they are declared.
|
public static final AttributeCachingStrategy SHOULD
The value should be cached to avoid excessive recalculation. This has roughly the same effect as MAY
.
One notable distinction is that if an attribute loader declares that the values should be cached, but then they are not cached (for example, if the values depend on other values, which must not be cached), the system will issue a warning in the logs.
public static final AttributeCachingStrategy MAY
public static final AttributeCachingStrategy SHOULD_NOT
The value should not be cached, although it potentially could be done.
There are two typical cases:
Project
object or any other bean-type value holder;Unlike MUST_NOT
, this caching strategy does not affect caching strategies of the dependent
attributes. If a value should not be cached (and is not cached), the derived values may still be cached if they have corresponding
caching strategies.
This means that the attribute loader using this caching strategies must not use some untraceable data when calculating the value. All dependent values will have to be invalidated with the usual updates to the item and, in case of multi-row loaders, the corresponding forest dependencies.
public static final AttributeCachingStrategy MUST_NOT
The value must not be cached. Use this strategy to indicate that the value is based on some untraceable data, so the attribute system will not know when it's time to invalidate and recalculate the value.
Declaring that the system must not cache the values coming from an attribute loader will also make values from all dependent loaders non-cacheable.
When strategies need to be combined (for example, when figuring out the final strategy based on dependencies), MUST_NOT
strategy
overrules any other strategy, because otherwise the values served might not be correct.
Try to avoid using this strategy! It may have adverse effect on performance, since the system will need to recalculate the values not only for this attribute, but for any dependent attributes too.
Consider alternatives to declaring the values to be non-cacheable, for example, setting a value timeout - see AttributeLoaderContext.valueExpires(long, java.util.concurrent.TimeUnit)
.
public static AttributeCachingStrategy[] values()
for (AttributeCachingStrategy c : AttributeCachingStrategy.values()) System.out.println(c);
public static AttributeCachingStrategy valueOf(String name)
name
- the name of the enum constant to be returned.IllegalArgumentException
- if this enum type has no constant with the specified nameNullPointerException
- if the argument is nullpublic static AttributeCachingStrategy guessCachingStrategy(AttributeSpec<?> spec)
Copyright © 2024 Tempo Software. All Rights Reserved.