From fe8e8b5d70aeba5711cab0fa9ac35555bfc96452 Mon Sep 17 00:00:00 2001
From: Tsvetoslav Tsekov <129774811+tsekovTriesCoding@users.noreply.github.com>
Date: Wed, 18 Mar 2026 15:20:44 +0200
Subject: [PATCH] feat: switch Spring Cloud LoadBalancer to Caffeine cache for
production
- Add spring-boot-starter-cache and caffeine dependencies to parent POM
- Configure LoadBalancer Caffeine cache in api-gateway (ttl=35s, capacity=256)
- Configure LoadBalancer Caffeine cache in auth-service (ttl=35s, capacity=256)
- Replaces default ConcurrentHashMap cache with production-recommended Caffeine
---
.../api-gateway/src/main/resources/application.yaml | 8 ++++++++
.../auth-service/src/main/resources/application.yaml | 8 ++++++++
backend/pom.xml | 12 ++++++++++++
3 files changed, 28 insertions(+)
diff --git a/backend/api-gateway/src/main/resources/application.yaml b/backend/api-gateway/src/main/resources/application.yaml
index 0d24aec..9297ac4 100644
--- a/backend/api-gateway/src/main/resources/application.yaml
+++ b/backend/api-gateway/src/main/resources/application.yaml
@@ -16,6 +16,14 @@ spring:
config:
enabled: false
+ loadbalancer:
+ cache:
+ enabled: true
+ ttl: 35s
+ capacity: 256
+ caffeine:
+ spec: initialCapacity=64,expireAfterWrite=35s
+
gateway:
discovery:
locator:
diff --git a/backend/auth-service/src/main/resources/application.yaml b/backend/auth-service/src/main/resources/application.yaml
index 7eac60e..07aad66 100644
--- a/backend/auth-service/src/main/resources/application.yaml
+++ b/backend/auth-service/src/main/resources/application.yaml
@@ -16,6 +16,14 @@ spring:
config:
enabled: false
+ loadbalancer:
+ cache:
+ enabled: true
+ ttl: 35s
+ capacity: 256
+ caffeine:
+ spec: initialCapacity=64,expireAfterWrite=35s
+
datasource:
url: jdbc:mysql://localhost:3306/finpay_auth?createDatabaseIfNotExist=true&useSSL=false&serverTimezone=UTC&allowPublicKeyRetrieval=true
username: ${MYSQL_USERNAME}
diff --git a/backend/pom.xml b/backend/pom.xml
index 0b12869..6527c85 100644
--- a/backend/pom.xml
+++ b/backend/pom.xml
@@ -148,6 +148,18 @@
micrometer-registry-prometheus
+
+
+ org.springframework.boot
+ spring-boot-starter-cache
+
+
+
+
+ com.github.ben-manes.caffeine
+ caffeine
+
+
org.springdoc