PHP图像生成器缓存

I have a script that takes an image and generates a resized version.

i.e. requesting /images/50x50-logo.png will call image-conroller.php which will then return a 50x50 version of logo.png

The image is returned using;

header('Content-Type: '.mime_content_type($sOutputPath));
readfile($sOutputPath);

As far as I'm aware, using this method to return the image, there is no safe way to check if the user already has a cached a version of this image. So how am I supposed to know if to send a 304 or serve the image?

Would someone please mind explaing if it's possible to achieve this. Or provide some direction to a soloution/workaround?

N.B. I can't think of a suitable title, any suggestions/edits would be apprecaited.