๐Ÿ–ฅ๏ธ

Real incidents need a real screen.

Open senioreng.dev on your laptop for the full experience.

Pull Request #5517

Cache tenant configs to reduce DB load

Adds a Redis caching layer for tenant configuration reads. Reduces Postgres load during peak traffic. 15-minute TTL with explicit cache eviction on config updates.

Ready to merge
cache/TenantConfigCache.java+38 additions
Viewed
1
@Component
2
public class TenantConfigCache {
3
@Autowired
4
private RedisTemplate<String, TenantConfig> redis;
5
6
private static final Duration TTL = Duration.ofMinutes(15);
8
+ public Optional<TenantConfig> get(Long tenantId, String region) {
9
+ String key = "config:" + tenantId;
10
+ return Optional.ofNullable(
11
+ redis.opsForValue().get(key));
12
+ }
13
+
14
+ public void put(Long tenantId, String region, TenantConfig config) {
15
+ String key = "config:" + tenantId;
16
+ redis.opsForValue().set(key, config, TTL);
17
+ }
18
+
19
+ public void evict(Long tenantId, String region) {
20
+ String key = "config:" + tenantId;
21
+ redis.delete(key);
22
+ }
23
+ }
PI

priya_infra

Approved review

Clean implementation. TTL is reasonable, eviction logic is correct. This will make a real dent in DB load. Approving.