Serving resized S3 images on the fly
#8 Caching requests
Let’s try to save AWS bandwidth with local cache
4 min readSep 3, 2022
If you didn’t notice — this is part of a series
In today’s publication, we will focus on optimization. We already have an MVP that works as intended. Only now can we try to speed it up. Remember that premature optimization is the root of all evil 😈
At the moment, I would like to do two quality refactors:
- change the method of returning the image source in the
ImageInterface
interface from a file to a closure that would return the image content. This optimization will help me delay the image transfer process from AWS servers until the image is necessary, i.e. in the conversion process, - change the method of returning the resized image from an
SplFileObject
to a simplestring
with the result to avoid unnecessary temporary files,
and three optimization related:
- store retrieved images from the sources in the local file store on the server to save transfer from AWS S3,
- store resized images in the local file store on the server to skip conversion process,
- include HTTP caching headers in the response.