On my Apache server I have a PHP service that gets requests and generates an image from them. What I want to do is to cache the genera开发者_开发百科ted image on my server (not client's browser) once it was generated, so if the image with specific parameters has been generated already and someone requests it my web server will return cached image instead of generating a new one.
I know I could store generated images on the server manually and on each request check if they exist, and then run cron tasks to remove expired images, but I am looking for more efficient way.
Thanks.
You already mentioned the most efficient way. Store it on disk. You could possibly use something like memcache, store it in memcache and then have memcache auto-expire the record after a certain amount of time.
Like you said, store it on the disk and read it back to the client. You could have ID.ext and ID.date where ID.date contains a expire date (in unix time). Then just compare what is in ID.date to what time() says, if time() is bigger than what ID.date is, then delete the two files and re-generate the image.
Depending on how you're generating the images, you might be able to use mod_cache to do your caching for you.
精彩评论