Assume I have a system in PHP that involves class discovery. The result of the class discovery is cached for performance.
Now I had the idea to attempt to clear or invalidate the cache, if the code changes. Either because a developer did something, or because a new version of a 3rd party library was downloaded.
One idea would be to compare file hashes for the class file. But doing this with e.g. md5(file_get_contents($file))
seems rather costly, and not something we want to do in every request / process.
Is there another, faster way to get hash for a PHP class, that produces a different result if the code changes?
I imagine that the answer is no, but one can always ask and hope.