David Wouldn't it be better to organize the miniatures by folders?
It's a good question, as I am considering changes to how image resize cache is stored, but I want to be sure before I make any changes, as it will affect existing users when they upgrade.
Storing cache in folders
_files/cache/original/path/filename.320.jpg could be useful, but it's a bit fragile. For example, if you (or someone) renames the folder or file manually, this can't be tracked by Files Gallery. Even if we are to automate cache when changes are done from within Files Gallery, this becomes a bit tedious ... If you rename a folder, we would need to search and change the path for all the corresponding files in cache dirs. Also, what happens if you rename a folder, and then rename another folder to the same name? You could end up with a cache filename.jpg that does not match the file in the corresponding folder. Another disadvantage, is that folders each take up a "node" on server, and some hosting / servers have restricted amount of nodes available.
I have also seen this setup before with cache stored in dirs, perhaps it was Koken? It's a good idea, but it's mostly useful when the application fully controls the file system and all changes are done from within the app. With Files Gallery, if someone makes changes outside the app, we can't track folders ... At best, it would be easier to manually manage cache.
Store file names without dir
Another idea I has, was to simply store
filename.filesize.jpg without the folder path. The
filesize would make sure the filename matches the original
filename, and the same cache can even be used for if the exact same file is stored in multiple dirs. Furthermore, you can move files around and rename folders, and it will still be able to use the same cached image. This method is a bit cheeky, but seems very powerful.
Hashed file names
With the current hashed cache file names, it's difficult to manage manually, but there is room for improvement. For example, I can easily create a "cache cleaner", that loops through dirs, compares with cache, and finally deletes the "unused" cache items. This script could be triggered manually, or even once on load.
Another option, is to store cache references in
_cache.json, and use this file to automate cleanup of unused cache files. If the original does not exist, then the cached file can be deleted of course.