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
|
|
@ -14,6 +14,11 @@ All notable changes to this project will be documented in this file.
|
|||
|
||||
- แก้ชนิด type ที่ reques
|
||||
|
||||
### ⚡ Performance
|
||||
|
||||
- Extended OrgStructureCache TTL from 10 to 30 minutes (reduce cleanup frequency)
|
||||
- Added OrgStructureCache.destroy() in graceful shutdown handler
|
||||
|
||||
### ⚙️ Miscellaneous Tasks
|
||||
|
||||
- Git-cliff changelog
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -146,6 +146,10 @@ async function main() {
|
|||
logMemoryStore.destroy();
|
||||
console.log("[APP] LogMemoryStore destroyed");
|
||||
|
||||
// Destroy OrgStructureCache
|
||||
orgStructureCache.destroy();
|
||||
console.log("[APP] OrgStructureCache destroyed");
|
||||
|
||||
clearTimeout(shutdownTimeout);
|
||||
console.log("[APP] Graceful shutdown completed");
|
||||
process.exit(0);
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ interface CacheEntry {
|
|||
|
||||
class OrgStructureCache {
|
||||
private cache: Map<string, CacheEntry> = new Map();
|
||||
private readonly CACHE_TTL = 10 * 60 * 1000; // 10 minutes
|
||||
private readonly CACHE_TTL = 30 * 60 * 1000; // 30 minutes
|
||||
private isInitialized = false;
|
||||
private cleanupTimer: NodeJS.Timeout | null = null;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ class OrgStructureCache {
|
|||
if (this.isInitialized) return;
|
||||
|
||||
this.isInitialized = true;
|
||||
// Cleanup expired entries every 10 minutes
|
||||
// Cleanup expired entries every 30 minutes
|
||||
this.cleanupTimer = setInterval(() => {
|
||||
this.cleanup();
|
||||
}, this.CACHE_TTL);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue