Cache Management
1. Overview
The admin-service uses Hazelcast as a distributed caching layer for both Spring @Cacheable application caches and Hibernate second-level (L2) entity caches. All cache data is shared across cluster members via Hazelcast distributed maps.
2. Cache Architecture
2.1. Spring Application Caches
These caches are managed by Spring’s CacheManager backed by HazelcastCacheManager.
| Cache Name | TTL | Purpose |
|---|---|---|
|
300s (5 min) |
Organisation access resolution for security queries |
|
300s (5 min) |
Person access resolution for security queries |
3. Why Restarting Does Not Clear Caches
During a rolling deployment:
-
Pod A holds cached data (including stale entries)
-
Pod B starts and joins the Hazelcast cluster
-
Pod B replicates cache data from Pod A
-
Pod A terminates
-
Pod B now holds the same stale cache data
This is by design — Hazelcast ensures high availability by replicating data across members. The only reliable way to clear stale data is to evict the cache via the API while the cluster is running.
4. Eviction Endpoints
All endpoints are under /management/cache-ops and require ROLE_ADMIN authentication (see Management API Access).
| Method | Endpoint | Description |
|---|---|---|
DELETE |
|
Evict both Spring and Hibernate L2 caches cluster-wide |
DELETE |
|
Evict Spring |
DELETE |
|
Evict Hibernate L2 entity cache regions only |
GET |
|
Cache names, sizes, and Hazelcast cluster member count |
Additionally, Spring Boot Actuator provides built-in cache endpoints:
| Method | Endpoint | Description |
|---|---|---|
GET |
|
List all Spring caches |
DELETE |
|
Evict all Spring caches |
DELETE |
|
Evict a specific Spring cache by name |
The built-in Actuator cache endpoints only cover Spring caches, not Hibernate L2 cache. Use /management/cache-ops/evict-all to clear both.
|
5. Operational Runbook
5.1. Scenario: Changed data in the database, application shows stale data
This is the most common scenario — you have updated records directly in the database and the application continues to serve old data.
# 1. Check current cache status
curl -H "X-API-KEY: <key>" https://<host>/management/cache-ops/status
# 2. Evict all caches (Spring + Hibernate L2)
curl -X DELETE -H "X-API-KEY: <key>" https://<host>/management/cache-ops/evict-all
# 3. Verify caches are cleared
curl -H "X-API-KEY: <key>" https://<host>/management/cache-ops/status
6. How Cluster-Wide Eviction Works
Both eviction paths propagate automatically to all cluster members:
-
Spring caches:
Cache.clear()calls HazelcastIMap.evictAll()which is a distributed operation -
Hibernate L2:
SessionFactory.getCache().evictAllRegions()delegates to Hazelcast map operations
There is no need to call each pod individually. A single API call to any cluster member clears the cache across all members.