You can use Refresh in an EAL action to check whether objects in the current ViewModel have changed on the persistence server, so clients connected through MDrivenServer can obtain current data when they need it.
Syntax
selfVM.Refresh
What Refresh does
Refresh asks the persistence server that implements SyncServer, such as MDrivenServer, whether any objects have changed since the previous refresh call.
If the server reports changed objects, it returns their identities. The client invalidates its local copies of those objects. When the application next needs an invalidated object, it retrieves a current copy from the persistence server.
This avoids reloading every object on each call. It lets multiple clients work with the same persisted information while transferring updated objects only when they are needed.
When to use it
Use Refresh when data may have been changed by another client or process and the current client must check for those changes.
For example, an order administrator changes an Order on one client. A second client that displays the same Order can call selfVM.Refresh. If the Order changed, the second client invalidates its local Order instance. When its ViewModel needs the Order data again, it obtains the updated version from the persistence server.
Add Refresh to an action
- Open the ViewModel that contains the action.
- Create or select the EAL action that should check for server-side changes.
- Add
selfVM.Refreshto the action. - Run the action while connected to the persistence server through SyncServer.
- When the action completes, use the affected data as normal. Objects reported as changed are retrieved again when the client needs them.
Important behavior
| Behavior | What it means |
|---|---|
| Checks for changes since the last call | Refresh does not request a complete reload of all data. It asks the server whether tracked objects changed after the preceding refresh check. |
| Invalidates changed local objects | The client marks the returned object identities as no longer current. It does not treat its existing local values as authoritative. |
| Loads current data on demand | An invalidated object is pulled again from the persistence server if the application needs it. |
| Requires SyncServer support | The persistence server must implement SyncServer, for example MDrivenServer, for Refresh to check server-side changes. |
Refresh compared with PSExpression_Refresh
Do not use Refresh to recompute database-driven aggregate fields in a ViewModel. For example, if a ViewModel column displays an order count calculated in the database, use PSExpression_Refresh to rerun the relevant PSExpression_ columns.
| Operator | Use it for |
|---|---|
selfVM.Refresh
|
Checking whether persisted objects changed and invalidating changed client-side objects. |
selfVM.PSExpression_Refresh()
|
Re-executing database-computed PSExpression_ ViewModel columns and updating their scalar results in the UI.
|
Example
A ViewModel shows an Order and its status. Another client can change that status. Add the following expression to an EAL action that checks for updates:
selfVM.Refresh
If the server identifies that Order as changed, the client invalidates its local Order object. The next time the ViewModel requires the Order status, it retrieves the current value from the persistence server.
