Should a binding cache updates?

I was making an addition to an existing binding and I noticed that the original binding author was caching the state and only issuing updateState to the BaseThingHandler if the value was different.

I didn’t think this was the preferred behavior for several reasons:

  1. Received Update won’t fire unless the state changes
  2. Suppression of events should happen (in most cases) in the framework not individual bindings

However, I can find nothing in the developer or other documents that indicates developers shouldn’t cache state updates in their binding.

Is there a best practice?

Based on my understanding, as a non-binding developer, is that in some cases it makes sense to only update on a change. Therefore I think it’s left up to the binding developer to make that decision on a case-by-case basis. From a user’s perspective, in almost all cases I would imagine that we would want to receive the updates, so long as the updates are meaningful in some way.

In general, unless there is some special reason, you should pass everything through to the system, and let the system deal with any filtering etc. for the reasons you have rightly point out :+1:


Let me give an example from a polling binding, Modbus.

Generally this is used to poll data for many channels at circa 1 second intervals.
When you’ve got a hundred Items, that’s a lot of update churn on the OH event bus, and also allows easy pitfalls e.g. persisting those updates can wallop your whole i/o subsystem.

An obvious approach is to only update on change, but Modbus binding offers a half-way solution. For each channel, an optional time parameter can be set. The effect is that if nothing changes, updates are passed to OH at the set time interval (well, when the next poll comes along in reality). One every 100 seconds, maybe.
In case of a change, it is passed immediately (and timer reset).
When required, setting 0 passes every update. Or you can set up to a week.

This requires caching on the part of the binding - the binding is supposed to be stateless but this bit of naughtiness is a real performance booster on limited platforms.


This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.