You use subscription to keep derived values current: data changes invalidate the expressions that depend on that data, so they are recalculated when their result is next read.
What subscribed means
A value is subscribed when it watches data for changes. If watched data changes, the subscriber receives an invalidation signal. The signal tells the subscriber that its current result may no longer be valid.
Subscribers are often OCL expressions. An expression is dependent on the model data that it reads while producing its result.
How cached expressions are updated
MDriven caches the result of an expression. Reading the expression does not require a new calculation when the cached result is still valid.
The result is calculated when either of these conditions applies:
- The expression has not previously been evaluated when its result is read.
- The expression has received an invalidation signal because data it depends on changed.
The following sequence describes the behavior:
- A consumer reads an expression result.
- If no cached result exists, the expression is evaluated and its result is cached.
- A change occurs in data used by that expression.
- The expression receives an invalidation signal.
- When a consumer next reads the expression result, MDriven evaluates the expression again and replaces the cached result.
Example
Assume an expression calculates an order total from the amounts of its order lines.
- The total is read for the first time. The expression calculates the sum and caches it.
- The total is read again without any order-line change. MDriven can return the cached total.
- An order-line amount changes. Because the total expression depends on that amount, the cached total is invalidated.
- The total is read again. The expression is recalculated, and the new result is cached.
The invalidation signal does not itself describe a new result. It marks the existing cached result as requiring recalculation on a later read.
Terms
| Term | Meaning |
|---|---|
| Subscriber | A value or expression that watches dependent data for changes. |
| Dependent data | Model data that an expression reads to produce its result. |
| Invalidation signal | A notification that dependent data changed and that a cached result may no longer be valid. |
| Cached result | A previously calculated expression result retained for later reads until it is invalidated. |
