I decided to go with combination of 1. and 5., plus file size check suggested by @Osyotr. User can select between "quick" and "strict" mode, plus command to invalidate cache.
original.filesize + '-' + encode(original.fullname)
, where encode
escapes any non-alphanumeric characters to ensure valid filename. Storing this info in filename allows quick mode to determine cache validity without reading either file.With the example program, here are some test cases and how they are handled in the two modes:
echo a > test.txt
- new file, no cache, both workecho b > test.txt
- modifies last write time, both workecho abc > test2.txt && mv test2.txt test.txt
- last write time unmodified but changes size, both workecho xyz > test2.txt && mv test2.txt test.txt
- last write time and size unmodified, quick mode fails but strict mode works