Hello everyone,
I have run into a limitation when using Asterisk Realtime together with the stale cache mechanism.
For realtime objects, Asterisk provides a cache and allows individual objects to be invalidated through AMI using stale or expire. This works very well in large deployments because it enables targeted updates. If the same process updates the database and invalidates the corresponding Asterisk cache entry, the cache remains consistent with the database.
However, the situation becomes more complicated in a high-availability environment.
In our setup, databases on different nodes are synchronized automatically. As a result, a change may be made on one node while another Asterisk instance continues to use a cached version of the object. The second node has no built-in way to determine whether the cached object is still consistent with the current database record.
In many systems, this problem is solved by introducing a revision field (or version field). The field receives a new unique value whenever the object is modified, and the cached revision can then be compared with the database revision to detect changes.
I would like to ask for advice on where such a field could be integrated so that, if implemented correctly, a patch would have a chance of being accepted into the official Asterisk sources.
At the moment, my preferred approach is to add an optional revision field to every PJSIP object, with an empty value by default. The field would be available both for Realtime and for static configuration. I believe it could also be useful for configuration-based deployments, not only Realtime.
My idea is intentionally simple: the field would not introduce any special processing by itself. It would only be loaded from Realtime/config sources and exposed through AMI, allowing external systems to implement revision tracking and cache validation logic.
What do you think about this approach? Are there better places in the architecture where such functionality should be implemented?