Changed LogMemoryStore from active refresh (setInterval) to passive refresh on-access (60 min TTL)

This commit is contained in:
Warunee Tamkoo 2026-01-29 00:30:34 +07:00
parent 7955c855bc
commit 656c2e7341
3 changed files with 32 additions and 22 deletions

View file

@ -104,15 +104,17 @@ class LogMemoryStore {
profileCache: Map<string, Profile>, // keycloak → Profile
rootIdCache: Map<string, string>, // profileId → rootId
};
private readonly REFRESH_INTERVAL = 10 * 60 * 1000; // 10 นาที
private readonly CACHE_TTL = 60 * 60 * 1000; // 60 นาที
}
```
**การทำงาน:**
- Cache `currentRevision` ทุก 10 นาที
- Passive cache refresh - ตรวจสอบและ refresh cache เมื่อมีการเข้าถึงข้อมูล (on-access)
- หาก cache เก่าเกิน 60 นาที จะทำการ refresh อัตโนมัติ
- Lazy load `profileCache` และ `rootIdCache` (โหลดเมื่อถูกเรียกใช้)
- Method `getProfileByKeycloak()` - ดึง profile จาก cache หรือ database
- Method `getRootIdByProfileId()` - ดึง rootId จาก cache หรือ database
- ไม่มี setInterval (ลดการใช้งาน timer)
#### 3.2 Log Middleware (`src/middlewares/logs.ts`)