The answer is that it depends.
There are two types of Etags, weak and strong. Weaknesses allow certain conditional operations to be performed, but most of them require strong etags.
The only restriction on a strong etag is that if the presentation changes for any reason, then etag. If it is a file, you can generate a hash, but it forces you to keep the object in memory during its creation. In addition, you can simply transfer the contents and add Etag as the final http-header, but almost no server currently supports this (very useful and unloved) functionality.
Ticks have a low resolution, and it is possible that two continuous entries in the same file will have the same number of ticks, even if the content is different. At this stage, the stage is now invalid if it is strong and you are in troubled waters. The same question as in Last-Modified. The way most HTTP servers are handled is to provide an etag file based on several of its properties, such as the timestamp, size, and possibly the identifier of the file object (inode in apache, possibly adding the full path to write the object store to NT and IIS adds a counter to this value, so two configuration changes on the server will generate different etags if something changes).
If you are using some kind of database, the id + version must be strong etag (provided that the content you ahve is not a combination of several things, each of which can change independently and without changing the root versions).
So, how to calculate this really depends on your scenario, and storing the file hash on recording (before starting the service) will probably help you, especially since it is a very useful feature for many other reasons.
SerialSeb
source share