* Checks if cache is stale based on timestamp (1 day)
( branch: string, forceLatest: boolean )
| 49 | * Checks if cache is stale based on timestamp (1 day) |
| 50 | */ |
| 51 | async function isCacheStale( |
| 52 | branch: string, |
| 53 | forceLatest: boolean |
| 54 | ): Promise<boolean> { |
| 55 | if (forceLatest) return true; |
| 56 | |
| 57 | const metadataPath = getCacheMetadataPath(branch); |
| 58 | if (!(await fs.pathExists(metadataPath))) { |
| 59 | return true; // No cache metadata, consider stale |
| 60 | } |
| 61 | |
| 62 | try { |
| 63 | const metadata: CacheMetadata = await fs.readJson(metadataPath); |
| 64 | const age = Date.now() - metadata.timestamp; |
| 65 | return age > CACHE_STALENESS_MS; |
| 66 | } catch (error) { |
| 67 | // If we can't read metadata, consider stale |
| 68 | return true; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | /** |
| 73 | * Saves cache metadata with timestamp |
no test coverage detected