Skip to content

Fix file cache to support offline usage of previously downloaded files#564

Open
Chessing234 wants to merge 1 commit intoallenai:mainfrom
Chessing234:fix/file-cache-offline
Open

Fix file cache to support offline usage of previously downloaded files#564
Chessing234 wants to merge 1 commit intoallenai:mainfrom
Chessing234:fix/file-cache-offline

Conversation

@Chessing234
Copy link
Copy Markdown

Summary

  • Fixes SciSpacy UmlsLinkerPaths Linker does not cache! #535: get_from_cache() always made an HTTP HEAD request before checking the local cache, causing failures when offline even if files were previously downloaded
  • Added _find_existing_cache_file() helper that checks for cached files by matching the URL hash prefix in the cache directory, avoiding any network calls
  • Wrapped the requests.head() call in a try/except for ConnectionError so that if no cached file exists and the network is unavailable, a clear error is raised instead of an unhandled exception

Test plan

  • Download a linker (e.g. umls) with network available, verify it caches correctly
  • Disconnect from network, re-run the same linker load, verify it returns the cached file without error
  • With no cached file and no network, verify a clear IOError is raised
  • Verify existing online-mode behavior is unchanged (fresh downloads still work)

🤖 Generated with Claude Code

The get_from_cache() function always made an HTTP HEAD request before
checking the local cache, which meant it failed when the network was
unavailable even if the file had been previously downloaded. This adds
a check for existing cached files before any network calls, so that
cached files are returned immediately. If no cached file exists and the
network is unavailable, a clear error message is raised.

Fixes allenai#535

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

SciSpacy UmlsLinkerPaths Linker does not cache!

1 participant