app
app copied to clipboard
Cache dynamic share images in Redis
The dynamic share images generated under the /api/share-images route are currently rendered from scratch on each request, but we should probably cache them for a day or so, because right now it's just generating unnecessary load.
Redis handles binary data just fine, so it should be pretty simple.
When rendering a share image, we need to check first whether the image is already on Redis, and serve it immediately if yes. If not, we should apply the same rendering logic as right now, and then save it to Redis in addition to returning it.
To do locally, run a redis server by e.g. running the official Redis Stack docker image, then connect the local app to it by setting CACHE_REDIS_CONNECTION_STRING
.
This logic should apply to all dynamic share image routes except the one for blog posts, because those are pre-rendered by the server anyway.