Repository navigation
feat: reuse the downloaded feed per instance for 60 seconds, add refresh() - #53
Merged
Merged
Conversation
Allow Pest 3.8/4/5 so every supported PHP version resolves, drop the always-on coverage and junit reports from phpunit.xml.dist, add PHP 8.5 to the matrices and run Tests and PHPStan on pull requests (push only on main).
…possible raintext times
…t/sun-stations-nearest
…feat/sun-stations-nearest
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #53 +/- ##
============================================
+ Coverage 84.74% 87.72% +2.98%
- Complexity 50 68 +18
============================================
Files 4 4
Lines 177 220 +43
============================================
+ Hits 150 193 +43
Misses 27 27 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
What
Every
forecast(),actualForecastForStation(),stations(),nearestStation(),sunrise()andsunset()call used to download and decode the whole JSON feed again (~35 KB).refresh()forces a new download ($buienradar->refresh()->forecast()).cacheSeconds(default 60,0turns caching off). Non-breaking: existingnew Buienradar()/new Buienradar($client)calls behave the same apart from the reuse.rainForecast()is not cached (different feed, per coordinate).hrtime()clock (a wall-clock jump can't stretch or cut the window), a negativecacheSecondsthrowsInvalidArgumentException, and the README states that failed downloads andrainForecast()aren't cached and thatrefresh()affects the next download (callforecast()again to reloadget()/report()).Usage
Tests
53 tests / 102 assertions pass, PHPStan level 8 clean. New
tests/FeedCacheTest.php: several different calls on one instance make one request and return the fixture data; the cache expires aftercacheSeconds;refresh()makes a second;cacheSeconds: 0disables reuse; a failed download is retried on the next call; a negative cache time is rejected. Live check:forecast(),stations(),sunrise()and a station lookup on one instance take 0.9 s in total (one download).Closes #42