Class DestinationService.Cache
- Enclosing class:
- DestinationService
- Since:
- 4.3.0
-
Field Summary
Modifier and TypeFieldDescriptionstatic final Duration
The default expiration duration of the destination cache.static final CacheExpirationStrategy
The defaultCacheExpirationStrategy
of the destination cache.static final long
The default size limit of the destination cache. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
disable()
Disables the entire destination cache.static void
Disables the "change detection" mode.static void
Disables the automatic entry expiration for the destination cache.static void
Disables the size limit of the destination cache.static void
Deprecated.since 5.2.0.static void
setExpiration
(Duration duration, CacheExpirationStrategy strategy) Sets the expiration duration and strategy for the destination cache.static void
setSizeLimit
(long size) Sets the size limit of the destination cache.
-
Field Details
-
DEFAULT_SIZE_LIMIT
public static final long DEFAULT_SIZE_LIMITThe default size limit of the destination cache.- See Also:
-
DEFAULT_EXPIRATION_DURATION
The default expiration duration of the destination cache. -
DEFAULT_EXPIRATION_STRATEGY
The defaultCacheExpirationStrategy
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 usingdisable()
instead.To allow the storage of an infinite number of cache entries, use
disableSizeLimit()
. You can still remove entries manually throughCacheManager.invalidateAll()
.
-
disableSizeLimit
public static void disableSizeLimit()Disables the size limit of the destination cache. You can still remove entries manually throughCacheManager.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 usingdisable()
instead.To allow storing entries forever, use
disableExpiration()
. You can still remove entries manually throughCacheManager.invalidateAll()
.strategy
- TheCacheExpirationStrategy
.
-
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 throughCacheManager.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
Deprecated.since 5.2.0. Change detection mode is enabled by defaultEnables 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. TheDestinationService.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
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
-