I have a question about caching in OH3. I use the http binding to query the API of the UK Environment Agency river level data. The readings are taken at the sites every 15 minutes but they are only published at that frequency when the flood risk is high. Fortunately, the API response includes a time stamp for the reading.
In OH1, I hit the API once and cached the result and then had two items, one for the reading and one for the timestamp. I want to optimise my use of the API so what it the best way to set this up?
At the, moment, I have the base URL as the thing and a channel for each reading I want to request, including the url extension. If I have two requests for the same extended url but with different jsonpath strings to get different parts of the response, will the binding query the API twice?
Thing http:url:riverstations "River Measuring Stations" [ baseURL="http://environment.data.gov.uk/flood-monitoring/id/measures/", refresh=900] {
Channels:
Type number : BuzzardLevel [ stateExtension="E21187-level-stage-i-15_min-m", stateTransformation="JSONPATH:$.items.latestReading.value", mode="READONLY" ]
Type DateTime : BuzzardTime [ stateExtension="E21187-level-stage-i-15_min-m", stateTransformation="JSONPATH:$.items.latestReading.dateTime", mode="READONLY" ]
Type number : ClipstoneLevel [ stateExtension="E21987-level-stage-i-15_min-m", stateTransformation="JSONPATH:$.items.latestReading.value", mode="READONLY" ]
Type number : ClipstoneTime [ stateExtension="E21987-level-stage-i-15_min-m", stateTransformation="JSONPATH:$.items.latestReading.dateTime", mode="READONLY" ]
}
What about if I create a thing with the extended url and then create two channels with no url extension but with the two different jsonpath strings?
Thing http:url:riverBuzzard "River Measuring Stations" [ baseURL="http://environment.data.gov.uk/flood-monitoring/id/measures/E21187-level-stage-i-15_min-m", refresh=900] {
Channels:
Type number : Level [ stateTransformation="JSONPATH:$.items.latestReading.value", mode="READONLY" ]
Type DateTime : Time [ stateTransformation="JSONPATH:$.items.latestReading.dateTime", mode="READONLY" ]
}
Thing http:url:riverClipstone "River Measuring Stations" [ baseURL="http://environment.data.gov.uk/flood-monitoring/id/measures/E21987-level-stage-i-15_min-m", refresh=900] {
Type number : Level [ stateTransformation="JSONPATH:$.items.latestReading.value", mode="READONLY" ]
Type number : Time [ stateTransformation="JSONPATH:$.items.latestReading.dateTime", mode="READONLY" ]
}
Either of these will work but I would prefer to be responsible and minimise the number of API calls.