ProcessWire-AIOM-All-In-One-Minify icon indicating copy to clipboard operation
ProcessWire-AIOM-All-In-One-Minify copied to clipboard

Cache filename collision

Open mackski opened this issue 8 years ago • 2 comments

If an array of filenames are passed, and all files have the same modified timestamp on separate pages a collision will occur and the wrong file is served for subsequent pages.

eg: Page 1 - array('file1.js','file2.js'); Page 2 - array('file1.js','file3.js');

Each file has the same timestamp (ie; rsync or similar copy operation).

Simple fix: $_timestamp = ($_timestamp + $file['last_modified'] . basename($file['absolute_path']));

mackski avatar Apr 21 '17 03:04 mackski

Got the same problem. I haven't tried your solution but isn't there a problem with adding a string to the timestamp because it is used for the arithmetic + operation in the next iteration? I did basically the same but using the decimal hash of the filename: $_timestamp = ($_timestamp + $file['last_modified'] + hexdec(md5(basename($file['absolute_path']))));

janKir avatar May 11 '17 15:05 janKir

We also had this problem. My fix:

private static function _getCacheName($files, $prefix = 'css_', $ext = '.css') {
    $hash = md5(print_r($files, true));

    return (self::$developmentMode !== true) ? $prefix.$hash.$ext : $prefix.$hash.'_dev'.$ext;
}

thuijzer avatar Jan 25 '18 13:01 thuijzer