Class PromotionCacheInvalidationHelper

java.lang.Object
com.broadleafcommerce.promotion.offer.service.messaging.cache.PromotionCacheInvalidationHelper

public class PromotionCacheInvalidationHelper extends Object
Provides supporting functionality related to cache invalidation components based on the getSupportedProjectionTypes() registered. This also provides the convenience of only having to declare those supporting types in one spot, rather than repeating that declaration (and possible code support) in multiple components.
  • Constructor Details

  • Method Details

    • init

      @PostConstruct public void init()
    • getNormalizedType

      @Nullable public Class<?> getNormalizedType(Class<?> candidateProjection)
      Get the top-most type based on a possibly more derived projection type.
      Parameters:
      candidateProjection - The possibly more derived projection type
      Returns:
      The top-most projection (if the candidate is derived). Otherwise, will return the candidateProjection passed in. Will return null if not found.
    • getProjectionType

      @Nullable public Class<?> getProjectionType(Class<?> domainType)
      Based on a repository domain type, retrieve the associated projection setup in the system.
      Parameters:
      domainType - The repository domain type
      Returns:
      The associated projection in the system. Will return null if not found.
    • mapProjection

      public Object mapProjection(Object entity)
      Given a repository domain instance, map to an instance of the associated projection.
      Parameters:
      entity - A repository domain instance
      Returns:
      An instance of the associated projection
    • shouldSendImmediately

      public boolean shouldSendImmediately(Class<?> projection)
      Whether or not the cache invalidation resulting from a mutation event for the given projection is configured to send immediately without a configured delay. Delays are generally specified for types in PromotionCacheInvalidationMessagingProperties, whose values are then expressed in the delay component of PromotionCacheInvalidationHelper.SupportedType in getSupportedProjectionTypes().
      Parameters:
      projection - The projection instance of the recently mutated entity
      Returns:
      Whether or not the cache invalidation should be sent without delay
    • getSendDelay

      @Nullable public Duration getSendDelay(Class<?> projection)
      Retrieve the send delay (if applicable) configured for the given projection type. See shouldSendImmediately(Class).
      Parameters:
      projection - The projection instance of the recently mutated entity
      Returns:
      The send delay (if applicable) configured for the given projection type. Will return null if not found.
    • getIdInformation

      @Nullable public com.broadleafcommerce.common.messaging.notification.IdInformation getIdInformation(Object projection, String channelModifier)
      Retrieve information used during message construction for notification of cache invalidation.
      Parameters:
      projection - The projection instance of the recently mutated entity
      channelModifier - A modifier key that is useful to match against a particular channel. See NotificationHandler.getChannelModifier().
      Returns:
      Id related information used during message construction. Will return null if the projection is not supported.
      See Also:
      • IdInformation
    • buildRemoteEvent

      public PromotionCacheInvalidationRemoteEvent buildRemoteEvent(Object projection)
      Build a cache invalidation event for a specific mutated entity
      Parameters:
      projection - The projection instance of the recently mutated entity
      Returns:
      The cache invalidation event for that entity
    • buildRemoteRegionEvent

      public PromotionCacheInvalidationRemoteEvent buildRemoteRegionEvent(Class<?> projection)
      Build a cache invalidation event for an entire cache region
      Parameters:
      projection - The class (region) for which all cache members should be evicted
      Returns:
      The cache invalidation event for that region
    • getSupportedProjectionTypes

      public List<PromotionCacheInvalidationHelper.SupportedType> getSupportedProjectionTypes()
    • setSupportedProjectionTypes

      public void setSupportedProjectionTypes(List<PromotionCacheInvalidationHelper.SupportedType> supportedProjectionTypes)