Topology-Wise Behavior for Cache Operations
NCache provides various caching topologies which behave differently on performing cache operations on them. Given below are NCache topologies and their behaviors.
In mirror topology, the client only communicates with the active node, while passive node is the replica of active node and is used for backup.
Bulk operations are performed on the active node, where the application waits for the operations to be replicated to the passive node.
Asynchronous operations are also performed on the active node, but the control is returned immediately to the application so it does not wait for the operation to be performed on both nodes. If callback is registered, it will be triggered upon success or failure of the operation.
In replicated topology, the client is connected to one node at a time. Thus, the bulk/async operations are sent to the specific node where the client is connected. These operations are then replicated among the nodes synchronously, ensuring data consistency.
In case of bulk operations, the operations are sent to the specific node where the client is connected. The control is returned to the user after replication has occurred on all nodes of the cluster.
For asynchronous operations, the control is returned immediately to the application, without waiting for replication to occur. However, once replication occurs, the callback is triggered and returned to the client.
In partitioned or partitioned-replica topology, a key-distribution map is maintained to distribute keys among multiple nodes. Any operation for the key will then be performed on the assigned node. When an operation is performed, key-value pairs are bundled according to the key-distribution map. These bundles are then sent to the assigned nodes of the clustered cache in a single call. This optimizes the operations and increases performance of the application.
In case of a bulk operation, for e.g. adding 100 items to cache, the operation will be performed on those nodes to which the keys belong, according to the key-distribution map. The control is returned after the operation is performed for all keys on the assigned nodes.
Asynchronous operations are atomic, and they are performed on the assigned node on the basis of the distribution map. The control is returned immediately to the client once the request for the operation is sent to the node.
In partitioned-replica topology, the client operation is performed on the assigned node at first, and then replicated to its replica either synchronously or asynchronously, as specified by the user.
In case of bulk operations, if in sync mode, the operations are performed on the assigned node and the application waits till replication occurs on the partition's replica. If in async mode, the control is returned to the application as soon the operation is performed on the partition node, and does not wait for replication as it is asynchronous.
In case of asynchronous operations, the operation is sent to the assigned partition node and the control is returned to the user immediately, irrespective of the specified sync mode.
A Client Cache is a local cache synchronized with a remote clustered cache. This synchronization occurs through polling - if a clustered cache detects a change for any of its client caches after its default poll interval of 1 second, it informs the client cache to poll the changed data. Otherwise, after its default interval of 10 seconds, the client cache requests the clustered cache to provide the changed data, if any.
In case of write operations, each operation is performed on the client cache first, and then subsequently performed on the remote cache through an internal Write-Behind mechanism.
For bulk operations, the control is returned to the application once the operation is performed on both client cache and remote cache. In case of asynchronous operations, callbacks are returned to the client cache from the remote cache after the operation is performed on cache.
However, for read operations, the key is first searched in client cache; if not found, the client cache will fetch the key item from the remote cache and then return it to the client. This provides maximum boost in performance and scalability of application without compromising the data integrity.