(prefix, feedUrl)
| 85 | } |
| 86 | |
| 87 | function getChangelogItemsFromCache(prefix, feedUrl) { |
| 88 | const cacheKey = getChangelogCacheKey(prefix, feedUrl) |
| 89 | |
| 90 | if (globalCache.get(cacheKey)) { |
| 91 | return globalCache.get(cacheKey) |
| 92 | } |
| 93 | |
| 94 | const diskCachePath = getDiskCachePath(prefix, feedUrl) |
| 95 | if (diskCachePath) { |
| 96 | try { |
| 97 | const payload = JSON.parse(fs.readFileSync(diskCachePath, 'utf-8')) |
| 98 | if (process.env.NODE_ENV === 'development') |
| 99 | console.log(`Changelog disk-cache HIT on ${diskCachePath}`) |
| 100 | // Also, for next time, within this Node process, put it into |
| 101 | // the global cache so we don't need to read from disk again. |
| 102 | globalCache.set(cacheKey, payload) |
| 103 | return payload |
| 104 | } catch (err) { |
| 105 | // If it wasn't on disk, that's fine. |
| 106 | if (err.code === 'ENOENT') return |
| 107 | // The JSON.parse() most likely failed. Ignore the error |
| 108 | // but delete the file so it won't be attempted again. |
| 109 | if (err instanceof SyntaxError) { |
| 110 | fs.unlinkSync(diskCachePath) |
| 111 | return |
| 112 | } |
| 113 | throw err |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | function setChangelogItemsCache(prefix, feedUrl, payload) { |
| 119 | const cacheKey = getChangelogCacheKey(prefix, feedUrl) |
no test coverage detected