Enum Class AttributeCachingStrategy
- All Implemented Interfaces:
Serializable
,Comparable<AttributeCachingStrategy>
,Constable
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.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E extends Enum<E>>
-
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionThe value may be cached.The value must not be cached.The value should be cached to avoid excessive recalculation.The value should not be cached, although it potentially could be done. -
Method Summary
Modifier and TypeMethodDescriptionstatic AttributeCachingStrategy
guessCachingStrategy
(AttributeSpec<?> spec) Guessing if the value is cacheable, based on the value format.static AttributeCachingStrategy
Returns the enum constant of this class with the specified name.static AttributeCachingStrategy[]
values()
Returns an array containing the constants of this enum class, in the order they are declared.
-
Enum Constant Details
-
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.
-
MAY
The value may be cached. The system will store the value in a cache unless there are other indications that it shouldn't. -
SHOULD_NOT
The value should not be cached, although it potentially could be done.
There are two typical cases:
- The value is a Java object that may become outdated - for example,
Project
object or any other bean-type value holder; - The value is very easy to calculate and it would be a waste of memory to store it.
Strategy propagation to dependent loaders
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.
- The value is a Java object that may become outdated - for example,
-
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.
Strategy propagation to dependent loaders
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.Performance implications
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)
.
-
-
Method Details
-
values
Returns an array containing the constants of this enum class, in the order they are declared.- Returns:
- an array containing the constants of this enum class, in the order they are declared
-
valueOf
Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)- Parameters:
name
- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException
- if this enum class has no constant with the specified nameNullPointerException
- if the argument is null
-
guessCachingStrategy
Guessing if the value is cacheable, based on the value format. A non-standard format will likely be an object like Project, which shouldn't be cacheable.
-