Skip to content

fix: evict stale cached images when Scryfall updates a scan#38

Open
spawnia wants to merge 4 commits into
DiddiZ:mainfrom
spawnia:stale-image-cache
Open

fix: evict stale cached images when Scryfall updates a scan#38
spawnia wants to merge 4 commits into
DiddiZ:mainfrom
spawnia:stale-image-cache

Conversation

@spawnia

@spawnia spawnia commented Apr 6, 2026

Copy link
Copy Markdown
Contributor

Newly spoiled cards often appear on Scryfall with a low-quality preview scan first, replaced by a proper scan later. We noticed this when printing a deck that included a recently spoiled card — the printed proxy showed the blurry early scan despite Scryfall having the correct image available.

Scryfall's image URIs already carry a Unix timestamp (e.g. …png?1774978609) that updates whenever the scan changes. The cache never checked it, so any image downloaded before the update would stay stale indefinitely.

To validate the fix, we planted a different card's image as the cached file for the affected card, set its mtime to one second before the URI timestamp, and printed the deck twice — once with the unfixed code (wrong card appeared in the PDF) and once with this fix applied (correct card, freshly downloaded).

During that validation we also discovered that the PDF printer derives cropped variants from the base file (e.g. png_front_<uuid>_14_14.png) and caches them alongside it, only regenerating them when missing. Evicting just the base left the stale variant in place, so the fix evicts those together with the base.

spawnia added 4 commits April 6, 2026 22:01
Scryfall embeds a Unix timestamp in each image URI (e.g. `…png?1774978609`)
that changes whenever the scan is updated. Previously, mtg-proxies cached
images indefinitely and never re-downloaded them, so users would keep
seeing outdated scans (e.g. early low-quality previews of newly spoiled
cards) until they manually cleared the cache.

get_image() now compares the cached file's mtime against the URI timestamp
and deletes the file before downloading when it is stale.
The PDF printer caches cropped variants of card images alongside the base
file (e.g. png_front_<uuid>_14_14.png). These are only generated when
missing, so evicting just the base left the stale variants in place and
the re-downloaded image was never used.

Evict all matching stem_*.png variants together with the base file.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant