* 清理过期项
()
| 215 | * 清理过期项 |
| 216 | */ |
| 217 | private cleanExpired(): void { |
| 218 | const now = Date.now(); |
| 219 | const expiredKeys: string[] = []; |
| 220 | |
| 221 | for (const [key, item] of Array.from(this.cache.entries())) { |
| 222 | if (now - item.timestamp > item.ttl) { |
| 223 | expiredKeys.push(key); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | expiredKeys.forEach(key => this.cache.delete(key)); |
| 228 | } |
| 229 | |
| 230 | /** |
| 231 | * 驱逐最不常用的项 |