Skip to content

Commit

Permalink
Update caching identifier to use etags
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassem Dghaidi committed Apr 28, 2021
1 parent 63bdbcc commit b7d297c
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ const calculate_pages = (options) => {
// about that here: https://developer.github.com/v3/#pagination
pages['total'] = /page=(?<last_page>[0-9]+)>; rel="last"/.exec(response.headers['link']).groups['last_page'];
pages['number_of_pages'] = Math.ceil(pages['total'] / 100);
pages['etag'] = response.headers['etag'];
return pages;
});
}
Expand Down Expand Up @@ -128,7 +129,7 @@ const search = (options) => {
*
* New data will be fetched and persisted on disk for future searches.
*/
let cacheHash = MurmurHash3(options.user).hash(pages.number_of_pages).result();
let cacheHash = MurmurHash3(options.user).hash(pages.etag).result();
let cache = flatCache.load(`${cacheHash}`, path.resolve(options.cacheDir));
if (cache._persisted.data === undefined || Object.keys(cache._persisted).length == 0) {
(options.verbose) ? console.log(chalk.bold.green('✅ INFO:: Cache is empty, fetching data from GitHub')) : null;
Expand Down

0 comments on commit b7d297c

Please sign in to comment.