| 139 | |
| 140 | const DATE_REGEX = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}.*Z$/; |
| 141 | const parseCache = (cached: string) => { |
| 142 | try { |
| 143 | return JSON.parse(cached, (_, value) => { |
| 144 | if (typeof value === 'string' && DATE_REGEX.test(value)) { |
| 145 | return new Date(value); |
| 146 | } |
| 147 | return value; |
| 148 | }); |
| 149 | } catch (error) { |
| 150 | console.error('Failed to parse cache', error); |
| 151 | return null; |
| 152 | } |
| 153 | }; |
| 154 | |
| 155 | // L1 cache: short TTL to offload Redis; clear() invalidates Redis, other nodes may serve stale from LRU for up to this long |
| 156 | const CACHEABLE_LRU_TTL_MS = 60 * 1000; // 60 seconds |