Avoid a race condition that can occur when writing cache files

file_put_contents() is used in putClassMetadataInCache(), which does not write files atomically so I added a check here to make sure we get an appropriate class object before blindly calling methods on it. Alternatively you could use an atomic write command and avoid this issue entirely.