feat: add response caching to minimize upstream API calls #3

Open
elia wants to merge 3 commits from feature/cache into master
Owner
  • Cache weather responses for 1 hour (3600 seconds)
  • Store cache in system-appropriate location (XDG on Linux, Library/Caches on macOS, LocalAppData on Windows)
  • Use SHA256 hash of URL as cache filename for uniqueness
  • Add --refresh flag to bypass cache and force fresh API call
  • Add --quiet-warnings flag to suppress cache fallback notifications
  • Add GO_CMW_QUIET_WARNINGS env var for multiplexer use cases
  • Fallback to cache on API failure with warning notification
  • Add comprehensive unit and integration tests with httptest mocks
  • Update README with caching documentation and examples

Cache flow:

  1. Check cache first (unless --refresh is set)
  2. If cache hit and valid (< 1 hour), return cached data
  3. If cache miss/expired, fetch from upstream API
  4. On success, cache response and return
  5. On failure, fallback to cache if available, else fatal error
- Cache weather responses for 1 hour (3600 seconds) - Store cache in system-appropriate location (XDG on Linux, Library/Caches on macOS, LocalAppData on Windows) - Use SHA256 hash of URL as cache filename for uniqueness - Add --refresh flag to bypass cache and force fresh API call - Add --quiet-warnings flag to suppress cache fallback notifications - Add GO_CMW_QUIET_WARNINGS env var for multiplexer use cases - Fallback to cache on API failure with warning notification - Add comprehensive unit and integration tests with httptest mocks - Update README with caching documentation and examples Cache flow: 1. Check cache first (unless --refresh is set) 2. If cache hit and valid (< 1 hour), return cached data 3. If cache miss/expired, fetch from upstream API 4. On success, cache response and return 5. On failure, fallback to cache if available, else fatal error
feat: add response caching to minimize upstream API calls
Some checks failed
Test Build / test-build (cmw-darwin-amd64, amd64, darwin) (push) Failing after 3s
Test Build / test-build (cmw-linux-amd64, amd64, linux) (push) Failing after 3s
Test Build / test-build (cmw-darwin-arm64, arm64, darwin) (push) Failing after 4s
Test Build / test-build (cmw-linux-arm64, arm64, linux) (push) Failing after 3s
Test Build / test-build (cmw-windows-amd64, amd64, windows) (push) Failing after 3s
Test / test (push) Failing after 3s
Test Build / test-build (cmw-darwin-amd64, amd64, darwin) (pull_request) Failing after 3s
Test Build / test-build (cmw-darwin-arm64, arm64, darwin) (pull_request) Failing after 4s
Test Build / test-build (cmw-linux-amd64, amd64, linux) (pull_request) Failing after 5s
Test Build / test-build (cmw-linux-arm64, arm64, linux) (pull_request) Failing after 3s
Test Build / test-build (cmw-windows-amd64, amd64, windows) (pull_request) Failing after 3s
Test / test (pull_request) Failing after 3s
deec15f4b2
- Cache weather responses for 1 hour (3600 seconds)
- Store cache in system-appropriate location (XDG on Linux, Library/Caches on macOS, LocalAppData on Windows)
- Use SHA256 hash of URL as cache filename for uniqueness
- Add --refresh flag to bypass cache and force fresh API call
- Add --quiet-warnings flag to suppress cache fallback notifications
- Add GO_CMW_QUIET_WARNINGS env var for multiplexer use cases
- Fallback to cache on API failure with warning notification
- Add comprehensive unit and integration tests with httptest mocks
- Update README with caching documentation and examples

Cache flow:
1. Check cache first (unless --refresh is set)
2. If cache hit and valid (< 1 hour), return cached data
3. If cache miss/expired, fetch from upstream API
4. On success, cache response and return
5. On failure, fallback to cache if available, else fatal error
elia force-pushed feature/cache from deec15f4b2
Some checks failed
Test Build / test-build (cmw-darwin-amd64, amd64, darwin) (push) Failing after 3s
Test Build / test-build (cmw-linux-amd64, amd64, linux) (push) Failing after 3s
Test Build / test-build (cmw-darwin-arm64, arm64, darwin) (push) Failing after 4s
Test Build / test-build (cmw-linux-arm64, arm64, linux) (push) Failing after 3s
Test Build / test-build (cmw-windows-amd64, amd64, windows) (push) Failing after 3s
Test / test (push) Failing after 3s
Test Build / test-build (cmw-darwin-amd64, amd64, darwin) (pull_request) Failing after 3s
Test Build / test-build (cmw-darwin-arm64, arm64, darwin) (pull_request) Failing after 4s
Test Build / test-build (cmw-linux-amd64, amd64, linux) (pull_request) Failing after 5s
Test Build / test-build (cmw-linux-arm64, arm64, linux) (pull_request) Failing after 3s
Test Build / test-build (cmw-windows-amd64, amd64, windows) (pull_request) Failing after 3s
Test / test (pull_request) Failing after 3s
to 7145568729
Some checks failed
Test Build / test-build (cmw-darwin-arm64, arm64, darwin) (pull_request) Successful in 2m0s
Test Build / test-build (cmw-darwin-amd64, amd64, darwin) (pull_request) Successful in 2m3s
Test Build / test-build (cmw-linux-amd64, amd64, linux) (pull_request) Successful in 2m7s
Test / skip-on-master (pull_request) Successful in 6s
Test Build / test-build (cmw-windows-amd64, amd64, windows) (pull_request) Successful in 2m13s
Test Build / test-build (cmw-linux-arm64, arm64, linux) (pull_request) Successful in 2m14s
Test / test (pull_request) Failing after 2m7s
2026-07-18 14:55:42 +00:00
Compare
fix(): Don't exit 1 if upstream is unavailable
All checks were successful
Test Build / test-build (cmw-linux-amd64, amd64, linux) (pull_request) Successful in 2m19s
Test Build / test-build (cmw-darwin-amd64, amd64, darwin) (pull_request) Successful in 2m20s
Test Build / test-build (cmw-darwin-arm64, arm64, darwin) (pull_request) Successful in 2m21s
Test Build / test-build (cmw-linux-arm64, arm64, linux) (pull_request) Successful in 2m15s
Test Build / test-build (cmw-windows-amd64, amd64, windows) (pull_request) Successful in 2m16s
Test / test (pull_request) Successful in 2m25s
2858403125
ci: split test-build into prepare/build/cleanup jobs with shared cache volumes
All checks were successful
Test Build / prepare (pull_request) Successful in 9s
Test Build / build (cmw-darwin-amd64, amd64, darwin) (pull_request) Successful in 2m10s
Test Build / build (cmw-darwin-arm64, arm64, darwin) (pull_request) Successful in 2m11s
Test / test (pull_request) Successful in 2m37s
Test Build / build (cmw-linux-arm64, arm64, linux) (pull_request) Successful in 2m18s
Test Build / build (cmw-linux-amd64, amd64, linux) (pull_request) Successful in 2m18s
Test Build / build (cmw-windows-amd64, amd64, windows) (pull_request) Successful in 2m10s
Test Build / cleanup (pull_request) Successful in 4s
cd40ea4849
All checks were successful
Test Build / prepare (pull_request) Successful in 9s
Test Build / build (cmw-darwin-amd64, amd64, darwin) (pull_request) Successful in 2m10s
Test Build / build (cmw-darwin-arm64, arm64, darwin) (pull_request) Successful in 2m11s
Test / test (pull_request) Successful in 2m37s
Test Build / build (cmw-linux-arm64, arm64, linux) (pull_request) Successful in 2m18s
Test Build / build (cmw-linux-amd64, amd64, linux) (pull_request) Successful in 2m18s
Test Build / build (cmw-windows-amd64, amd64, windows) (pull_request) Successful in 2m10s
Test Build / cleanup (pull_request) Successful in 4s
This pull request can be merged automatically.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin feature/cache:feature/cache
git switch feature/cache

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch master
git merge --no-ff feature/cache
git switch feature/cache
git rebase master
git switch master
git merge --ff-only feature/cache
git switch feature/cache
git rebase master
git switch master
git merge --no-ff feature/cache
git switch master
git merge --squash feature/cache
git switch master
git merge --ff-only feature/cache
git switch master
git merge feature/cache
git push origin master
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
elia/go-cmw!3
No description provided.