fix: extend OrgStructureCache TTL and add graceful shutdown cleanup
- Extended OrgStructureCache TTL from 10 to 30 minutes (reduce cleanup frequency) - Added orgStructureCache.destroy() in graceful shutdown handler - Updated documentation to reflect changes Co-Authored-By: Claude (glm-4.7) <noreply@anthropic.com>
This commit is contained in:
parent
e4cfac2eb2
commit
7955c855bc
4 changed files with 18 additions and 5 deletions
|
|
@ -65,7 +65,11 @@ const gracefulShutdown = async (signal: string) => {
|
|||
|
||||
// 3. ทำลาย cache instances
|
||||
logMemoryStore.destroy();
|
||||
console.log("[APP] LogMemoryStore destroyed");
|
||||
|
||||
// Destroy OrgStructureCache
|
||||
orgStructureCache.destroy();
|
||||
console.log("[APP] OrgStructureCache destroyed");
|
||||
|
||||
// 4. บังคับปิดหลังจาก 30 วินาที (หาก shutdown ค้าง)
|
||||
const shutdownTimeout = setTimeout(() => {
|
||||
|
|
@ -134,7 +138,7 @@ const profile = await logMemoryStore.getProfileByKeycloak(keycloak);
|
|||
```typescript
|
||||
class OrgStructureCache {
|
||||
private cache: Map<string, CacheEntry>;
|
||||
private readonly CACHE_TTL = 10 * 60 * 1000; // 10 นาที
|
||||
private readonly CACHE_TTL = 30 * 60 * 1000; // 30 นาที
|
||||
|
||||
// Key format: org-structure-{revisionId}-{rootId}
|
||||
private generateKey(revisionId: string, rootId?: string): string
|
||||
|
|
@ -147,9 +151,9 @@ class OrgStructureCache {
|
|||
|
||||
**การทำงาน:**
|
||||
- Cache ผลลัพธ์ของ org structure ตาม `revisionId` และ `rootId`
|
||||
- TTL 10 นาที - ข้อมูลเก่าจะถูกลบอัตโนมัติ
|
||||
- TTL 30 นาที - ข้อมูลเก่าจะถูกลบอัตโนมัติ (ปรับจาก 10 นาที เพื่อลด cleanup frequency)
|
||||
- Method `invalidate()` - ลบ cache เมื่อมีการอัปเดต revision
|
||||
- Auto cleanup ทุก 10 นาที
|
||||
- Auto cleanup ทุก 30 นาที
|
||||
|
||||
**การใช้งานใน API:**
|
||||
```typescript
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue