-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information
Showing
10 changed files
with
82 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import { expect } from 'chai' | ||
import nock from 'nock' | ||
import { getCachedResource, clearResourceCache } from './resource-cache.js' | ||
|
||
describe('Resource Cache', function () { | ||
beforeEach(function () { | ||
clearResourceCache() | ||
}) | ||
|
||
it('should use cached response if valid', async function () { | ||
let resp | ||
|
||
nock('https://www.foobar.com').get('/baz').reply(200, { value: 1 }) | ||
resp = await getCachedResource({ url: 'https://www.foobar.com/baz' }) | ||
expect(resp).to.deep.equal({ value: 1 }) | ||
expect(nock.isDone()).to.equal(true) | ||
nock.cleanAll() | ||
|
||
nock('https://www.foobar.com').get('/baz').reply(200, { value: 2 }) | ||
resp = await getCachedResource({ url: 'https://www.foobar.com/baz' }) | ||
expect(resp).to.deep.equal({ value: 1 }) | ||
expect(nock.isDone()).to.equal(false) | ||
nock.cleanAll() | ||
}) | ||
|
||
it('should not use cached response if expired', async function () { | ||
let resp | ||
|
||
nock('https://www.foobar.com').get('/baz').reply(200, { value: 1 }) | ||
resp = await getCachedResource({ | ||
url: 'https://www.foobar.com/baz', | ||
ttl: 1, | ||
}) | ||
expect(resp).to.deep.equal({ value: 1 }) | ||
expect(nock.isDone()).to.equal(true) | ||
nock.cleanAll() | ||
|
||
nock('https://www.foobar.com').get('/baz').reply(200, { value: 2 }) | ||
resp = await getCachedResource({ | ||
url: 'https://www.foobar.com/baz', | ||
ttl: 1, | ||
}) | ||
expect(resp).to.deep.equal({ value: 2 }) | ||
expect(nock.isDone()).to.equal(true) | ||
nock.cleanAll() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters