ImageBundle icon indicating copy to clipboard operation
ImageBundle copied to clipboard

sha1 hashing don't use modification time?

Open freyr opened this issue 11 years ago • 3 comments

In documentation there is info about how cache name is created: "Each operation above is not actually applied on the opened image, but added in an operations array. This operation array, the name, type and modification time of file are hashed using sha1() and the hash is used to look up for a cache file."

As far as i can read the code, there is no time part inside the sha1 method (generateHash). Because of that if I replace source file with another content, browsers will hit internal cache, as name is the same... Is there somewhere solution for that problem?

freyr avatar Feb 07 '14 13:02 freyr

Hi, This was done in the past. Now, this is the work of Gregwar/Cache, that checks that the target file is younger than the source.

I did this to avoid generating a lot of target files just because the original time has changed.

If you want to force your client browsers to reload the file, a solution could be adding the filectime() result as a get parameter, like:

<img src="/cache/some/hashed/file.jpg?<filectime_timestamp>" />

Gregwar avatar Feb 07 '14 13:02 Gregwar

Filectime checks file createtime, but You can use filemtime that check file last modification time. AFAIK there aren't other reasons than changing file content that can result in different filemtime value. If You add into sha algorithm filemtime value, then only if file was altered sha will change. This solution will be more general that manually add filemtime to every request...

Can you see drawback of this approach?

freyr avatar Feb 10 '14 09:02 freyr

Yes I understand, and this is how it was implemented in the first versions, but the problem was that multiple cache files will be created, on each modification you will generate a new cache file I think this way is better because it uses less disk spaces without any garbage collect or cache regeneration required.

Maybe we could add an option to the bundle to add automatically the filemtime to force client reloading?

Gregwar avatar Feb 10 '14 09:02 Gregwar