Cache keys should not be the same (#1223)
Fix the cache bug introduced in #1186 that blocked today's deploy.
This commit is contained in:
@@ -97,7 +97,7 @@ function handleRequest (handlerOptions) {
|
||||
// Use sindresorhus query-string because it sorts the keys, whereas the
|
||||
// builtin querystring module relies on the iteration order.
|
||||
const stringified = queryString.stringify(filteredQueryParams);
|
||||
const cacheIndex = `match[0]?${stringified}`;
|
||||
const cacheIndex = `${match[0]}?${stringified}`;
|
||||
|
||||
// Should we return the data right away?
|
||||
const cached = requestCache.get(cacheIndex);
|
||||
@@ -199,5 +199,7 @@ function clearRequestCache() {
|
||||
|
||||
module.exports = {
|
||||
handleRequest,
|
||||
clearRequestCache
|
||||
clearRequestCache,
|
||||
// Expose for testing.
|
||||
_requestCache: requestCache
|
||||
};
|
||||
|
||||
@@ -8,7 +8,8 @@ const analytics = require('./analytics');
|
||||
const { makeBadgeData: getBadgeData } = require('./badge-data');
|
||||
const {
|
||||
handleRequest,
|
||||
clearRequestCache
|
||||
clearRequestCache,
|
||||
_requestCache
|
||||
} = require('./request-handler');
|
||||
|
||||
const baseUri = `http://127.0.0.1:${config.port}`;
|
||||
@@ -113,6 +114,24 @@ describe('The request handler', function() {
|
||||
'/testing/123.svg?foo=2'
|
||||
).then(() => { assert.equal(handlerCallCount, 1); });
|
||||
});
|
||||
|
||||
describe('the cache key', function () {
|
||||
const expectedCacheKey = '/testing/123.json?colorB=123&label=foo';
|
||||
it('should match expected and use canonical order - 1', function () {
|
||||
return fetch(`${baseUri}/testing/123.json?colorB=123&label=foo`)
|
||||
.then(res => {
|
||||
assert.ok(res.ok);
|
||||
assert.deepEqual([..._requestCache.cache.keys()], [expectedCacheKey]);
|
||||
});
|
||||
});
|
||||
it('should match expected and use canonical order - 2', function () {
|
||||
return fetch(`${baseUri}/testing/123.json?label=foo&colorB=123`)
|
||||
.then(res => {
|
||||
assert.ok(res.ok);
|
||||
assert.deepEqual([..._requestCache.cache.keys()], [expectedCacheKey]);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('custom query parameters', function() {
|
||||
|
||||
Reference in New Issue
Block a user