<h1 dir="auto">Bug report</h1>
<p dir="auto"><strong>What is the current behavior?</strong><br>
Assume we have two projects with only index.js files in them, which are having same content:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/938036/122017048-4c2c6d80-cdca-11eb-909a-6f0acbb36152.png"><img src="https://user-images.githubusercontent.com/938036/122017048-4c2c6d80-cdca-11eb-909a-6f0acbb36152.png" alt="image" style="max-width: 100%;"></a></p>
<p dir="auto">and this webpack config:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="module.exports = {
  mode: 'production',
  cache: {
    type: 'filesystem'
  },
  infrastructureLogging: {
    level: 'info',
    debug: /webpack\.cache.*/,
  },
  entry: `./${process.env.SRC_DIR}/index.js`,
  plugins: [
    new MiniCssExtractPlugin({ filename:'styles.[chunkhash].css' })
  ],
  output: {
    pathinfo: false,
  },
  module: {
    rules: [{
      test: /\.(js|jsx)$/,
      loader: 'babel-loader',
      options: {
        &quot;plugins&quot;: [
          &quot;syntax-dynamic-import&quot;,
          &quot;@babel/plugin-proposal-class-properties&quot;
        ],
        &quot;presets&quot;: [
            [
                &quot;@babel/preset-env&quot;,
                {
                    &quot;modules&quot;: false
                }
            ],
            &quot;@babel/preset-react&quot;
        ]
      }
    }]
  },

  optimization: {
    minimizer: [new TerserPlugin({

    })],
  }
}"><pre class="notranslate"><code class="notranslate">module.exports = {
  mode: 'production',
  cache: {
    type: 'filesystem'
  },
  infrastructureLogging: {
    level: 'info',
    debug: /webpack\.cache.*/,
  },
  entry: `./${process.env.SRC_DIR}/index.js`,
  plugins: [
    new MiniCssExtractPlugin({ filename:'styles.[chunkhash].css' })
  ],
  output: {
    pathinfo: false,
  },
  module: {
    rules: [{
      test: /\.(js|jsx)$/,
      loader: 'babel-loader',
      options: {
        "plugins": [
          "syntax-dynamic-import",
          "@babel/plugin-proposal-class-properties"
        ],
        "presets": [
            [
                "@babel/preset-env",
                {
                    "modules": false
                }
            ],
            "@babel/preset-react"
        ]
      }
    }]
  },

  optimization: {
    minimizer: [new TerserPlugin({

    })],
  }
}
</code></pre></div>
<p dir="auto">After cache warmup with <code class="notranslate">webpack5-1</code> repo we build first <code class="notranslate">webpack5-1</code> and then - <code class="notranslate">webpack5-2</code></p>
<p dir="auto">warmup time:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="webpack 5 - 1 (warmup) : 5.05401289999485 seconds"><pre class="notranslate"><code class="notranslate">webpack 5 - 1 (warmup) : 5.05401289999485 seconds
</code></pre></div>
<p dir="auto">Full compilation time with cache is then following:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="webpack 5 - 1: 0.8312232999801635 seconds
webpack 5 - 2: 1.4813145999908448 seconds"><pre class="notranslate"><code class="notranslate">webpack 5 - 1: 0.8312232999801635 seconds
webpack 5 - 2: 1.4813145999908448 seconds
</code></pre></div>
<p dir="auto">After that, if we not delete <code class="notranslate">.cache</code> folder and again build  <code class="notranslate">webpack5-1</code> and then - <code class="notranslate">webpack5-2</code> then builds aree took almost the same time</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="webpack 5 - 1: 0.8569822000265122 seconds
webpack 5 - 2: 0.9038357999920845 seconds"><pre class="notranslate"><code class="notranslate">webpack 5 - 1: 0.8569822000265122 seconds
webpack 5 - 2: 0.9038357999920845 seconds
</code></pre></div>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
Reproducing steps in readme section of repo <a href="https://github.com/SkReD/webpack5-performance-issue/tree/cache-share-problem">https://github.com/SkReD/webpack5-performance-issue/tree/cache-share-problem</a></p>
<p dir="auto"><strong>What is the expected behavior?</strong><br>
Expect compilation time to be almost the same for both <code class="notranslate">webpack5-1</code> and <code class="notranslate">webpack5-2</code> with cache from the first one.</p>
<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.38.1<br>
Node.js version: 14.17.0<br>
Operating System: windows 10 x64<br>
Additional tools:</p>
<h2 dir="auto">Feature request</h2>





<p dir="auto"><strong>What is the expected behavior?</strong></p>
<p dir="auto">right now cache writes absolute paths</p>
<p dir="auto"><strong>What is motivation or use case for adding/changing the behavior?</strong></p>
<p dir="auto">if all paths will be relative to cache folder it will allow to share cache</p>
<p dir="auto"><strong>How should this be implemented in your opinion?</strong></p>
<p dir="auto">Did not investigate this, yet</p>
<p dir="auto"><strong>Are you willing to work on this yourself?</strong></p>
<p dir="auto">Yes</p>