Lemmy doesn’t so much cache the images so much as “store them forever”.
Regular post thumbnails are just “internal” images. I’m not sure if newer Lemmy versions log these internally like user uploads are, but assuming not, there’s no direct way to deal with them.
Pict-rs keeps a true cache of image variants (alternate versions of images that were requested at different resolutions / formats). Those can be cleared programmatically:
curl -XDELETE -H "X-Api-token:YOUR_API_KEY" http://127.0.0.1:8080/internal/variants
Where your pict-rs API port is exposed to localhost on port 8080. Also note that those variants will be re-created on demand.
One easy-ish way to get rid of images is to select from the post
table for any thumbnail_url
that starts with your instance. e.g. https://your-instance/pictrs/image/%s
. You can filter that by published
date if you only want to wipe out thumbnails for posts older than a year, for example.
With that list, you can strip off the filename/alias (the uuid and extension) and pass each alias filename to a script that tells pict-rs to delete it (you need at least pict-rs 0.5 for this to work):
#!/bin/bash
ALIAS="$1"
API_KEY=FooBarAPIKeyIsFake
curl -XPOST -H "X-Api-token:$API_KEY" http://127.0.0.1:8080/internal/delete?alias=%24ALIAS
Below 0.5, the only way to delete images fro pict-rs without the delete token was to use the purge endpoint. But that deletes all aliases and not just the one you want to delete since it does de-duplication under the hood.
If you want to get fancy so that image posts still render correctly, when building your list of thumbnails to delete, you can check if the value of the url
column is an image. If it is, grab the current thumbnail image to pass to the delete function and then update the thumbnail URL value to that of the post URL.
Hope they don’t “rush in” to any conclusions.