Closed francescobm closed 6 years ago
These are considered different by default (runkit example).
Code:
const cachios = require('cachios');
const url = 'http://example.com/';
const logStats = promise => promise.then(() => console.log(cachios.cache.getStats()));
// should be miss (hits = 0, misses = 1)
await logStats(cachios.get(`${url}?country_code=fr-fr`));
// should also be miss (hits = 0, misses = 2)
await logStats(cachios.get(`${url}?country_code=de-de`));
// should be hit (hits = 1, misses = 2)
await logStats(cachios.get(`${url}?country_code=fr-fr`));
// should be hit (hits = 2, misses = 2)
await logStats(cachios.get(`${url}?country_code=de-de`));
Cache keys are determined based on Custom Cache Identifiers. By default, it looks like this:
function defaultCacheIdentifer(config) {
return {
method: config.method,
url: config.url,
params: config.params,
data: config.data,
};
}
Which takes into account method (GET, POST), the full URL, and query params (in the params object), and any data in the request body.
Would cachios consider
/nav/?country_code=fr-fr
and/nav/?country_code=de-de
the same?