From 948ce408f25366c0843cda6a4cafac696d6d939f Mon Sep 17 00:00:00 2001 From: Avgustin Marinov Date: Mon, 27 Oct 2025 09:47:47 +0200 Subject: [PATCH] Sync cache doc with the last update (#2776) Signed-off-by: Avgustin Marinov --- docs/clustering.md | 6 ++---- .../eclipse/hawkbit/tenancy/TenantAwareCacheManager.java | 9 ++++++++- .../src/main/resources/application.properties | 2 +- .../java/org/eclipse/hawkbit/rest/RestConfiguration.java | 7 ++++--- site/content/guides/clustering.md | 5 ++--- 5 files changed, 17 insertions(+), 12 deletions(-) diff --git a/docs/clustering.md b/docs/clustering.md index 5dab3d8c2..e5bcf7c3b 100644 --- a/docs/clustering.md +++ b/docs/clustering.md @@ -32,13 +32,11 @@ serviceMatcher.isFromSelf(event) ### Caching -Every node is maintaining its own caches independent from other nodes. +Every node is maintaining its own caches independent of the other nodes. So there is no globally shared/synchronized cache instance within the cluster. In order to keep nodes in sync, a **TTL (time to live)** can be set for all caches to ensure that after some time the cache is refreshed from the database. -To enable the TTL just set the property `hawkbit.cache.global.ttl` (value in milliseconds). - -Of course, you can implement a shared cache, e.g. Redis. See [CacheAutoConfiguration](https://github.com/eclipse-hawkbit/hawkbit/blob/master/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java). +To enable the TTL just set the property `hawkbit.cache.global.ttl` (value in dDhHmMsS format). --- diff --git a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAwareCacheManager.java b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAwareCacheManager.java index 52e3fbe5b..2ef6ea81c 100644 --- a/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAwareCacheManager.java +++ b/hawkbit-core/src/main/java/org/eclipse/hawkbit/tenancy/TenantAwareCacheManager.java @@ -19,6 +19,7 @@ import com.github.benmanes.caffeine.cache.Caffeine; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; import org.eclipse.hawkbit.tenancy.TenantAware.TenantResolver; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.cache.Cache; @@ -34,6 +35,7 @@ import org.springframework.lang.Nullable; *
  • If no tenant is resolved, a global cache manager is used.
  • * */ +@Slf4j @NoArgsConstructor(access = AccessLevel.PRIVATE) @SuppressWarnings("java:S6548") // singleton holder ensures static access to spring resources in some places public class TenantAwareCacheManager implements CacheManager { @@ -115,7 +117,12 @@ public class TenantAwareCacheManager implements CacheManager { spec = defaultSpec; } } - return new CaffeineCache(n, Caffeine.from(spec).build(), false); + try { + return new CaffeineCache(n, Caffeine.from(spec).build(), false); + } catch (final IllegalArgumentException e) { + log.error("Invalid cache spec: {}", spec, e); + throw new IllegalStateException("Invalid cache spec: " + spec, e); + } }); } diff --git a/hawkbit-monolith/hawkbit-update-server/src/main/resources/application.properties b/hawkbit-monolith/hawkbit-update-server/src/main/resources/application.properties index dac11c1e6..b53cfc9d7 100644 --- a/hawkbit-monolith/hawkbit-update-server/src/main/resources/application.properties +++ b/hawkbit-monolith/hawkbit-update-server/src/main/resources/application.properties @@ -39,7 +39,7 @@ hawkbit.server.ddi.security.authentication.gatewaytoken.enabled=false # Cache configuration, # disable expiration since monolith is expected to be used as an all-in-one hawkBit instance, # i.e. no microservices and 1 replica, then evict should do work -hawkbit.cache.ttl=0 +hawkbit.cache.ttl=0s # Optional events hawkbit.server.repository.publish-target-poll-event=false diff --git a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java index 13e98f403..ca2f90bd1 100644 --- a/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java +++ b/hawkbit-rest-core/src/main/java/org/eclipse/hawkbit/rest/RestConfiguration.java @@ -181,7 +181,7 @@ public class RestConfiguration { * @param ex the exception which occurred * @return the entity to be responded containing the response status 500 */ - @ExceptionHandler(FileStreamingFailedException.class) + @ExceptionHandler({ FileStreamingFailedException.class, IllegalStateException.class }) public ResponseEntity handleFileStreamingFailedException(final HttpServletRequest request, final Exception ex) { logRequest(request, ex); @@ -274,8 +274,9 @@ public class RestConfiguration { return new ResponseEntity<>(createExceptionInfo(new MultiPartFileUploadException(responseCause)), HttpStatus.BAD_REQUEST); } - @ExceptionHandler({DataIntegrityViolationException.class}) - public ResponseEntity handleDataAccessException(final HttpServletRequest request, final DataIntegrityViolationException ex) { + @ExceptionHandler({ DataIntegrityViolationException.class }) + public ResponseEntity handleDataAccessException(final HttpServletRequest request, + final DataIntegrityViolationException ex) { if (log.isDebugEnabled()) { logRequest(request, ex); } else { diff --git a/site/content/guides/clustering.md b/site/content/guides/clustering.md index 11c00446b..4d00991fb 100644 --- a/site/content/guides/clustering.md +++ b/site/content/guides/clustering.md @@ -77,11 +77,10 @@ Add to your `pom.xml` : ## Caching -Every node is maintaining its own caches independent from other nodes. So there is no globally shared/synchronized cache +Every node is maintaining its own caches independent of the other nodes. So there is no globally shared/synchronized cache instance within the cluster. In order to keep nodes in sync a TTL (time to live) can be set for all caches to ensure that after some time the cache is refreshed from the database. To enable the TTL just set the property " -hawkbit.cache.ttl" (value in milliseconds). Of course you can implement a shared cache, e.g. Redis. -See [CacheAutoConfiguration](https://github.com/eclipse-hawkbit/hawkbit/blob/master/hawkbit-autoconfigure/src/main/java/org/eclipse/hawkbit/autoconfigure/cache/CacheAutoConfiguration.java) +hawkbit.cache.ttl" (value in format dDhHmMsS). ## Schedulers