MCPcopy Create free account
hub / github.com/github/docs / getChangelogItemsFromCache

Function getChangelogItemsFromCache

lib/changelog.js:87–116  ·  view source on GitHub ↗
(prefix, feedUrl)

Source from the content-addressed store, hash-verified

85}
86
87function 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
118function setChangelogItemsCache(prefix, feedUrl, payload) {
119 const cacheKey = getChangelogCacheKey(prefix, feedUrl)

Callers 1

getChangelogItemsFunction · 0.85

Calls 2

getChangelogCacheKeyFunction · 0.85
getDiskCachePathFunction · 0.85

Tested by

no test coverage detected