index.js
function afterEmit(compilation, callback) {
    var failures;
    if (options.persist) {
      var cache    = compilation.cache,
          filePath = path.resolve(options.file);

      stats.serialise.encode.start = Date.now();
      var encoded = encode(cache);
      failures = (encoded.$failed || [])
        .filter(filterIgnored);
      delete encoded.$failed;
      stats.serialise.encode.stop = Date.now();

      stats.failures = failures.length;

      // abort
      if (failures.length) {
        stats.serialise.fs.start = Date.now();
        fs.unlink(filePath, complete.bind(null, true));
      }
      // serialise and write file
      else {
        stats.serialise.decycle.start = Date.now();
        var decycled = cycle.decycle(encoded);
        stats.serialise.decycle.stop = Date.now();

        stats.serialise.fs.start = Date.now();
        var buffer = new Buffer(JSON.stringify(decycled, null, 2));
        stats.serialise.size = buffer.length;
        fs.writeFile(filePath, buffer, complete);
      }
    }
    else {
      failures = [];
      complete();
    }

    function complete(error) {
      stats.serialise.fs.stop = Date.now();
      stats.serialise.success = !error;
      options.warn && pushFailures(failures, compilation.warnings, (options.warn === 'verbose'));
      options.stats && printStats(stats);
      callback();
    }
  }
function afterEmit(compilation, callback) {
    var failures;
    if (options.persist) {
      var cache    = compilation.cache,
          filePath = path.resolve(options.file);

      stats.serialise.encode.start = Date.now();
      var encoded = encode(cache);
      failures = (encoded.$failed || [])
        .filter(filterIgnored);
      delete encoded.$failed;
      stats.serialise.encode.stop = Date.now();

      stats.failures = failures.length;

      // abort
      if (failures.length) {
        stats.serialise.fs.start = Date.now();
        fs.unlink(filePath, complete.bind(null, true));
      }
      // serialise and write file
      else {
        stats.serialise.decycle.start = Date.now();
        var decycled = cycle.decycle(encoded);
        stats.serialise.decycle.stop = Date.now();

        stats.serialise.fs.start = Date.now();
        var buffer = new Buffer(JSON.stringify(decycled, null, 2));
        stats.serialise.size = buffer.length;
        fs.writeFile(filePath, buffer, complete);
      }
    }
    else {
      failures = [];
      complete();
    }

    function complete(error) {
      stats.serialise.fs.stop = Date.now();
      stats.serialise.success = !error;
      options.warn && pushFailures(failures, compilation.warnings, (options.warn === 'verbose'));
      options.stats && printStats(stats);
      callback();
    }
  }
function afterEmit ( compilation , callback ) { var failures ; if ( options . persist ) { var cache = compilation . cache , filePath = path . resolve ( options . file ) ; stats . serialise . encode . start = Date . now ( ) ; var encoded = encode ( cache ) ; failures = ( encoded . $failed || [ ] ) . filter ( filterIgnored ) ; delete encoded . $failed ; stats . serialise . encode . stop = Date . now ( ) ; stats . failures = failures . length ; // abort if ( failures . length ) { stats . serialise . fs . start = Date . now ( ) ; fs . unlink ( filePath , complete . bind ( null , true ) ) ; } // serialise and write file else { stats . serialise . decycle . start = Date . now ( ) ; var decycled = cycle . decycle ( encoded ) ; stats . serialise . decycle . stop = Date . now ( ) ; stats . serialise . fs . start = Date . now ( ) ; var buffer = new Buffer ( JSON . stringify ( decycled , null , 2 ) ) ; stats . serialise . size = buffer . length ; fs . writeFile ( filePath , buffer , complete ) ; } } else { failures = [ ] ; complete ( ) ; } function complete ( error ) { stats . serialise . fs . stop = Date . now ( ) ; stats . serialise . success = ! error ; options . warn && pushFailures ( failures , compilation . warnings , ( options . warn === 'verbose' ) ) ; options . stats && printStats ( stats ) ; callback ( ) ; } }
Serialise the cache to file, don't wait for async.
Serialise the cache to file don t wait for async .