sounisi5011/metalsmith-netlify-published-date

The has() method of the "PreviewCache" class probably won't work

Opened this issue · 1 comments

The has() method should verify whether the cache data corresponding to the url specified in the argument exists.
However, the code when using the flat-cache package is probably not in line with its purpose.

See line 47:

public has(url: string): boolean {
if (this._store instanceof Map) {
return this._store.has(url);
} else {
return this.isCachedPreviewResponseJSON(this._store.all().url);
}
}

This code always looks like reading the cached data stored in the url property.

Is the correct code not this? :

return this.isCachedPreviewResponseJSON(this._store.all()[url]);
//                                                       ^^^^^

Thank you for pointing out important issues!
Perhaps I wrote this code while sleeping 💦

Fortunately, we do not use the PreviewCache class has() method at now.
has() method was added to make it work as a Map class compatible interface.

However, this bug may cause problems if you use the has() method in the future.
This project requires test code of PreviewCache class.