Now that we have Room DB properly set up,
we can modify the repository, given that all existing API interfaces unchanged,
we can introduce classic caching mechanism, so that when it receives an API request:
It checks the local DB if the required data set exists (we store half-hourly consumption only - and we expect 48 records a day to be "exists")
If we have enough local data, we simply return that locally
Otherwise we run API call and cache them before returning them to the caller
Characteristics:
We in some ways also introduce offline mode - because it won't trigger HTTP error as we don't fire HTTP requests
During British Summer Time, when we only have 2 records for yesterday, the simple integrity check will always invalidate that, and we always retry until a full set of 48 meter readings are returned.
We know there can be gaps for some customers due to smart meter communication errors, and the number of records during BST transitions is not exactly 48. We will address this in Autumn 2024 when we have the real data.
This enables speeding up the actual bill calculation when we are under non-half-hourly views, as these can be reused to avoid repeated API calls.
Now that we have Room DB properly set up, we can modify the repository, given that all existing API interfaces unchanged, we can introduce classic caching mechanism, so that when it receives an API request:
Characteristics: