Extracting cache storage#3898
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extracts cache persistence into a new StorageComponent/StorageLocalFiles backend and migrates several existing “cache to config_root/cache” implementations to use the shared storage abstraction.
Changes:
- Add a new
apps/predbat/storage.pystorage component (async save/load/age + expiry metadata + periodic cleanup) and register it in the component registry. - Migrate Solcast/Open-Meteo/Forecast.Solar caching in
SolarAPI.cache_get_url()and Solcast/Forecast.Solar on-disk caches to use the storage component. - Persist/restore GE Cloud settings and FutureRate URL cache via storage; add unit tests for the storage backend and the migrated behaviors.
Reviewed changes
Copilot reviewed 14 out of 15 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| requirements.txt | Adds aiofiles dependency for async filesystem I/O in the new storage backend. |
| apps/predbat/storage.py | Introduces the storage backend + component wrapper and cache cleanup logic. |
| apps/predbat/components.py | Registers the new storage component in phase 0. |
| apps/predbat/component_base.py | Adds ComponentBase.storage convenience accessor for components. |
| apps/predbat/solcast.py | Switches URL caching and Solcast/Forecast.Solar caches to the storage backend. |
| apps/predbat/gecloud.py | Restores/saves inverter settings + GE URL cache via the storage backend. |
| apps/predbat/futurerate.py | Loads/saves FutureRate URL cache via the storage backend. |
| apps/predbat/predbat.py | Removes legacy futurerate_url_cache initialization from reset state. |
| apps/predbat/userinterface.py | Removes legacy futurerate_url_cache from the debug exclude list. |
| apps/predbat/unit_test.py | Registers the new storage test suite in the main test runner. |
| apps/predbat/tests/test_storage.py | Adds unit tests for storage round-trip, expiry, cleanup, and age semantics. |
| apps/predbat/tests/test_solcast.py | Updates SolarAPI cache tests to use storage rather than direct filesystem JSON. |
| apps/predbat/tests/test_ge_cloud.py | Updates GE cache tests and adds tests for settings save/restore behavior via storage. |
| apps/predbat/tests/test_futurerate_auto.py | Adds tests asserting FutureRate cache load/save via storage. |
| .cspell/custom-dictionary-workspace.txt | Adds aiofiles to the spelling dictionary. |
Comment on lines
+235
to
+238
| # Store data in cache with 7-day expiry | ||
| if self.storage and data: | ||
| expiry = datetime.now(timezone.utc) + timedelta(days=7) | ||
| await self.storage.save("solar", hash_key, data, format="json", expiry=expiry) |
| except (ValueError, TypeError): | ||
| return None | ||
| if dt.tzinfo is None: | ||
| dt = dt.replace(tzinfo=timezone.utc) |
Comment on lines
+60
to
+61
| separators embedded in the identifier. | ||
| """ |
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.
No description provided.