Clean up cache module; affects [feedz jenkinsplugin myget node nuget packagist travis wordpress] (#7319)

* update terminology
    - "regular update" to "cached resource"
    - "interval" to "ttl"
    - move file and update imports

* set a default TTL, don't explicitly pass params if we want the default

* add tests

* update docs
This commit is contained in:
chris48s
2021-11-29 21:21:03 +00:00
committed by GitHub
parent 8355793520
commit feb1682814
10 changed files with 82 additions and 40 deletions

View File

@@ -1,6 +1,6 @@
import moment from 'moment'
import semver from 'semver'
import { regularUpdate } from '../../core/legacy/regular-update.js'
import { getCachedResource } from '../../core/base-service/resource-cache.js'
const dateFormat = 'YYYY-MM-DD'
@@ -9,9 +9,8 @@ async function getVersion(version) {
if (version) {
semver = `-${version}.x`
}
return regularUpdate({
return getCachedResource({
url: `https://nodejs.org/dist/latest${semver}/SHASUMS256.txt`,
intervalMillis: 24 * 3600 * 1000,
json: false,
scraper: shasums => {
// tarball index start, tarball index end
@@ -36,10 +35,8 @@ async function getCurrentVersion() {
}
async function getLtsVersions() {
const versions = await regularUpdate({
const versions = await getCachedResource({
url: 'https://raw.githubusercontent.com/nodejs/Release/master/schedule.json',
intervalMillis: 24 * 3600 * 1000,
json: true,
scraper: ltsVersionsScraper,
})
return Promise.all(versions.map(getVersion))