Open GoogleCodeExporter opened 9 years ago
Actually the a/a.js has newer modification date.
And, a/old/a.js has older modification date.
ETag should do a hash matching on the content.
But currently, minify is serving from the cache, without comparing ETag.
NOTE: minify works correctly if I place a newer modified file, so
"If-Modified-Since"
works properly.
Original comment by ruj.sa...@gmail.com
on 21 May 2009 at 3:10
I appreciate the report, but I probably won't fix this.
Currently Minify's cache invalidates if the mtime(source) > mtime(cache). This
involves only a few quick filemtime() calls (fast), requires simple logic and
requires no metadata be stored in the cache file, allowing us to serve it very
fast
with readfile().
Your very reasonable request is for the cache to invalidate when
content(source) !=
content(cache), but there are a few reasons I'm not interested in this (today):
1. It seems like a rare use case (replacing source files with those with old
mtimes)... source control/archive exports might cause this, but if you have to
do
this, you (or your build process) could easily empty the cache directory, or
touch()
the replaced files. Perhaps this warrants documentation on the wiki.
2. It would severely hit performance and require drastic changes. At the very
minimum, on each request PHP would need to run md5_file() on each source file
(yikes), and at least read several bytes of metadata (either in the cache file
or a
separate file) to verify the hashes match.
This cost could be offset somewhat by storing an expiration timestamp for the
cache
file, then invalidating it when that time is reached. This approach would force
source editors to wait to see changes in the minified files unless they
manually
remove cache files, but would at least save Minify from having to read the
contents
of source files on every request.
In short: I'd prefer to keep the current fast, simple, imperfect caching system.
Original comment by mrclay....@gmail.com
on 21 May 2009 at 6:12
Can't we take different an approach for calculating an ETag?
For example: combination of filemtime() and filesize()? Or, something quick
like
that?
This will prevent from calculating expensive md5 of the whole file.
This will be very helpful to simplify the build process.
Original comment by ruj.sa...@gmail.com
on 21 May 2009 at 6:50
I agree, it will not be perfect calculation for ETag.
But it will work *most* of the time (there will be rare chance of failure when
a file
has different content but same size and same modification date).
Original comment by ruj.sa...@gmail.com
on 21 May 2009 at 6:56
Hmm. We really don't need an expiration on the cache file, but rather a
throttle for
the validation checks. In other words, for cache validation we could do this
(pseudocode):
Func isCacheFileValid(abc) {
// if returns false we'd rebuild abc and abc_hash
If is_file(abc) && is_file(abc_hash):
If filemtime(abc_hash) over 3 seconds old:
Check md5_file(sources) vs contents(abc_hash)
If match:
Touch(abc_hash). Return true.
Else:
Return false.
Else:
Return true.
Else:
Return false.
}
Now on busy server w/ 100s req/s, the vast majority of cache validations will
require only 1 filemtime() and 2 is_file()s, which may even be a performance
increase. On a development server, at most the designer would have to wait 3
seconds
to see a change in what Minify serves.
This would still be a big undertaking, so I wouldn't hold your breath, but I'll
at
least keep it on the table.
Original comment by mrclay....@gmail.com
on 21 May 2009 at 8:59
Original issue reported on code.google.com by
ruj.sa...@gmail.com
on 21 May 2009 at 3:05Attachments: