Class DestinationService.Cache

java.lang.Object
com.sap.cloud.sdk.cloudplatform.connectivity.DestinationService.Cache
Enclosing class:
DestinationService

@Beta public static final class DestinationService.Cache extends Object
Helper class that encapsulates all caching related configuration options.
Since:
4.3.0
  • Field Details

    • DEFAULT_SIZE_LIMIT

      public static final long DEFAULT_SIZE_LIMIT
      The default size limit of the destination cache.
      See Also:
    • DEFAULT_EXPIRATION_DURATION

      public static final Duration DEFAULT_EXPIRATION_DURATION
      The default expiration duration of the destination cache.
    • DEFAULT_EXPIRATION_STRATEGY

      public static final CacheExpirationStrategy DEFAULT_EXPIRATION_STRATEGY
      The default CacheExpirationStrategy of the destination cache.
  • Method Details

    • disable

      public static void disable()
      Disables the entire destination cache.

      Caution: This method is not thread-safe.

      Caution: Using this operation will lead to a deletion of the destination cache. As a consequence, destinations will always be fetched from the destination service, which might be slow.

    • setSizeLimit

      public static void setSizeLimit(@Nonnegative long size)
      Sets the size limit of the destination cache.

      Please note that the size limit only applies for the cache of individual destinations.

      Caution: This method is not thread-safe.

      Caution: Using this operation will lead to a re-creation of the destination cache. As a consequence, all existing cache entries will be lost.

      Parameters:
      size - The size limit.

      Using a size of 0 will effectively disable the cache, as it won't store any values. Consider using disable() instead.

      To allow the storage of an infinite number of cache entries, use disableSizeLimit(). You can still remove entries manually through CacheManager.invalidateAll().

    • disableSizeLimit

      public static void disableSizeLimit()
      Disables the size limit of the destination cache. You can still remove entries manually through CacheManager.invalidateAll().

      Caution: This method is not thread-safe.

      Caution: Using this operation will lead to a re-creation of the destination cache. As a consequence, all existing cache entries will be lost. Additionally, using an unbounded cache might lead to memory exhaustion.

    • setExpiration

      public static void setExpiration(@Nonnull Duration duration, @Nonnull CacheExpirationStrategy strategy)
      Sets the expiration duration and strategy for the destination cache.

      In case change detection is enabled, this sets the interval in which the cache will check for changes. In that case, the given strategy will only be applied to the cache for all destinations.

      Caution: This method is not thread-safe.

      Caution: Using this operation will lead to a re-creation of the destination cache. As a consequence, all existing cache entries will be lost.

      Parameters:
      duration - The expiration duration.

      Using a duration of Duration.ZERO will effectively disable the cache, as all entries will expire immediately. Consider using disable() instead.

      To allow storing entries forever, use disableExpiration(). You can still remove entries manually through CacheManager.invalidateAll().

      strategy - The CacheExpirationStrategy.
    • disableExpiration

      public static void disableExpiration()
      Disables the automatic entry expiration for the destination cache. Destinations will still be fetched if the attached JWT token is expired. Additionally, you can still remove entries manually through CacheManager.invalidateAll().

      Caution: This method is not thread-safe.

      Caution: Using this operation will lead to a re-creation of the destination cache. As a consequence, all existing cache entries will be lost. Changes of the destination configuration via, for example, the BTP cockpit will not be picked up for as long as the destination is within the cache - this might be forever depending on the configured cache size.

    • enableChangeDetection

      @Beta @Deprecated public static void enableChangeDetection()
      Deprecated.
      since 5.2.0. Change detection mode is enabled by default
      Enables the so-called "change detection" mode.

      Enabling the change detection mode has the following implications:
      1. Destinations will be cached for a longer period of time.
      2. The DestinationService.Cache will regularly check for updates in the Destination service.
      3. Individual destinations will be re-fetched from the Destination service if either (A) an authentication token is expired (same behavior as without the change detection mode) or (B) the destination has been updated recently in the Destination service (e.g. via the BTP Cockpit), or (C) the destination references a certificate.

      The interval at which the SDK checks for changes can be configured via setExpiration(Duration, CacheExpirationStrategy).

      The change detection mode can significantly improve caching performance as individual destination may stay cached much longer while still staying response with regard to changes in the Destination service. In other words: Instead of doing (unnecessary) expensive destination retrievals for individual destinations, there is only one cheap request to the Destination service that is valid for all destinations at once.

      Please note that certificate based destinations are not cached for longer. Because if a certificate changes but keeps the same name, the change can not be detected by the SDK. In other words, the change detection feature does not apply to certificate based destinations, they are cached as if this was disabled.

      Caution: This method is not thread-safe.

      Caution: Using this operation will lead to a re-creation of the destination cache. As a consequence, all existing cache entries will be lost.

      Since:
      4.7.0
    • disableChangeDetection

      @Beta public static void disableChangeDetection()
      Disables the "change detection" mode.

      Caution: Using this operation will lead to a re-creation of the destination cache.

      Since:
      5.2.0