Key STAC cache by AOI and fetch parameters (fixes silent cross-AOI collision) - #26
Merged
NewGraphEnvironment merged 6 commits intoJul 7, 2026
Merged
Conversation
The cache filename was <year>.nc under a per-source directory — no AOI component. Two calls with the same source/year but different AOIs collided: the second silently got the first AOI's raster masked to its own extent. Add internal stac_cache_key(): rlang::hash() over the AOI geometry as WKB plus res (coerced to double), target CRS, dt, aggregation, resampling, and post-resolution stac_url/collection/asset. Filename becomes <year>_<key>.nc; year stays out of the hash so all years of one call share a readable suffix. Existing caches simply refetch; dft_cache_clear() reclaims the old files. Relates to #25 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
force = TRUE routed to the fetch branch but write_ncdf errored on the
existing file ("File already exists"), so force could never bypass a stale
cache without a manual unlink. Pass overwrite = TRUE instead; unlike a bare
unlink() this still fails loudly if the file is locked (Windows). Document
in @param force that a previously returned raster backed by the same file
may pick up the rewritten contents.
Fixes #25
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Relates to #25 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
NewGraphEnvironment
deleted the
25-dft-stac-fetch-cache-key-omits-aoi-secon
branch
July 7, 2026 04:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
dft_stac_fetch(): cache files were keyed by source + year only, so a second AOI silently received the first AOI's raster masked to its own extent. Cache filenames now embed a hash of the AOI geometry (as WKB) and all fetch-affecting parameters (res,crs,dt,aggregation,resampling,stac_url,collection,asset):<year>_<key>.nc.force = TRUEnow overwrites the cached NetCDF (write_ncdf(..., overwrite = TRUE)) instead of erroring with "File already exists".@param force), NEWS entry, released as v0.2.3. Existing caches simply re-fetch;dft_cache_clear()reclaims orphaned old-format files.Fixes #25
Related Issues
Test plan
devtools::test(): 192 pass, 0 fail (5 new local cache-key tests — determinism, geometry/parameter sensitivity, integer-vs-doubleres, sf-attribute immunity)lintrclean on touched files (one pre-existing vignette lint, untouched)force = TRUEoverwrites without error/code-checkclean on each commitNotes
Design details (WKB geometry hashing to avoid PROJ-version CRS drift, hashing post-resolution config values, why the issue's optional extent check was skipped) are in
planning/archive/2026-07-issue-25-cache-key-aoi/.🤖 Generated with Claude Code