fix: cache with locale

This commit is contained in:
Yanlong Wang 2024-08-30 18:37:23 +08:00
parent 6900e0241c
commit 42700d1a85
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37

View File

@ -100,6 +100,9 @@ export class CrawlerHost extends RPCHost {
// Potential privacy issue, dont cache if cookies are used // Potential privacy issue, dont cache if cookies are used
return; return;
} }
if (options.locale) {
Reflect.set(snapshot, 'locale', options.locale);
}
await this.setToCache(options.url, snapshot); await this.setToCache(options.url, snapshot);
}); });
@ -1025,7 +1028,10 @@ ${suffixMixins.length ? `\n${suffixMixins.join('\n\n')}\n` : ''}`;
cache = await this.queryCache(urlToCrawl, cacheTolerance); cache = await this.queryCache(urlToCrawl, cacheTolerance);
} }
if (cache?.isFresh && (!crawlOpts?.favorScreenshot || (crawlOpts?.favorScreenshot && (cache.screenshotAvailable && cache.pageshotAvailable)))) { if (cache?.isFresh &&
(!crawlOpts?.favorScreenshot || (crawlOpts?.favorScreenshot && (cache.screenshotAvailable && cache.pageshotAvailable))) &&
(_.get(cache.snapshot, 'locale') === crawlOpts?.locale)
) {
yield this.jsdomControl.narrowSnapshot(cache.snapshot, crawlOpts); yield this.jsdomControl.narrowSnapshot(cache.snapshot, crawlOpts);
return; return;