Reputation: 1505
To make it short and firm:
I have an api which returns a md5 of a specific file. The files are about 50 - 100 MB large. Now my question is:
What would need less resources/is stylistic better:
FileSystemWatcher
for changes and refresh the md5 if the file changesIt was told me that generating a md5 many times could produce a overheat.
Upvotes: 0
Views: 358
Reputation: 3043
The best approach is to compute the MD5 beforehand, and save the MD5 along with the main file.
Computing it dynamically on the first call adds complexity and processing time that can easily be avoided.
Upvotes: 0
Reputation: 7459
Second option will always be faster, how significantly depends on how often the file changes.
The most processing consuming operation you have is the MD5 hashing. If you have no choice but to hash the file with MD5, you should do all you can to reduce the number of times you do it. The ideal scenario would be to do it only once, which is exactly what would be doing with option 2.
That's supposing the file won't change, but definitely the chances to produce an overheat should be much lower than option 1, even if you change the file once every 5 minutes.
Upvotes: 2