cache-loader icon indicating copy to clipboard operation
cache-loader copied to clipboard

Do not rely on file `mtime`

Open jdeniau opened this issue 7 years ago • 8 comments

npm 5.8+ set file mtime to October 1985 (See https://github.com/npm/npm/issues/20439 ), it's a feature for them, so the cache-loader does not work anymore.

Furthermore, https://github.com/webpack-contrib/cache-loader/commit/f24f723 tells to not trust file mtime.

Should we relly on file content hash instead ?

jdeniau avatar May 23 '18 10:05 jdeniau

@jdeniau need tests mtime vs md4 from hash content. PR welcome :+1:

alexander-akait avatar May 23 '18 10:05 alexander-akait

Maybe this could be slightly more generic, can supply a custom compare function for the comparison callback?

LukeSheard avatar Sep 18 '18 19:09 LukeSheard

:+1: for the PR made by @LukeSheard

luislobo avatar Oct 15 '18 17:10 luislobo

My diagnosis might not be correct, but I think this problem is impacting us as well. We have some custom loaders in our project written in TypeScript. When we run a build, we compile the TypeScript to JavaScript before running webpack - giving the custom loaders a new mtime. The loaders are added as dependencies by cache-loader, thus we can never get cached content.

Any chance the PR from @LukeSheard could be revived?

bencoveney avatar Mar 01 '19 15:03 bencoveney

is this fixed?

sibelius avatar Mar 11 '20 14:03 sibelius

@sibelius no, cache-loader is low priority due webpack@5 will have built-in cache, anyway if you want to fix something PR welcome

alexander-akait avatar Mar 11 '20 14:03 alexander-akait

For the record, I do not use cache-loader anymore, as webpack does a fine job now like @evilebottnawi said.

jdeniau avatar Mar 11 '20 23:03 jdeniau

I attempted to workaround this by comparing based on ctime, but unfortunately only mtime is stored in the cache.

So ultimately, I went with the approach recommended in webpack's docs: use a postinstall hook to remove the node_modules/.cache/cache-loader folder.

https://webpack.js.org/guides/build-performance/#persistent-cache

scottrippey avatar Jun 26 '20 20:06 scottrippey