Enum Class AttributeCachingStrategy

Object
Enum<AttributeCachingStrategy>
AttributeCachingStrategy
All Implemented Interfaces:
Serializable, Comparable<AttributeCachingStrategy>, Constable

@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.

See Also:
  • Enum Constant Details

    • SHOULD

      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.

    • MAY

      public static final AttributeCachingStrategy 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

      public static final AttributeCachingStrategy 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.

    • MUST_NOT

      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.

      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

      public static AttributeCachingStrategy[] 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

      public static AttributeCachingStrategy valueOf(String name)
      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 name
      NullPointerException - if the argument is null
    • guessCachingStrategy

      public static AttributeCachingStrategy guessCachingStrategy(AttributeSpec<?> spec)
      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.