Basic Cache Operations
NCache provides various CRUD APIs for caching data. The data can be a single item or in bulk, and can be used synchronously and asynchronously, as desired. This section caters all the basic APIs to add, update, delete or remove data to/from cache.
Synchronous Operations
NCache allows adding either an atomic item or items in bulk - synchronously. Since synchronous operations are performed as a blocking call, the client has to wait for the response from the server to execute further operations. The control is returned to the application once the operation has been completely performed.
Even though the client has to wait for operation completion, sync operations allow returning the success/failure status of the operation as the control is returned to the user. An operation may fail due to connection failure with the cache or any internal system reason. This provides your application with the control to handle any failure scenarios as soon as they are encountered, providing more failure safety.
Furthermore, synchronous operations are sequential; one operation has to be completed in order for the other to begin. This is useful if your operations are dependent of each other, the behavior of one operation is the input of the succeeding operation. For example, an e-commerce site synchronously adds items which are on flash sale for 2 hours only. The next task of your application requires retrieving those items which have a flash sale. Hence, accuracy will only be achieved if the items have been added to cache first, so the exact items can be fetched from the cache.
Asynchronous Operations
NCache supports both synchronous and asynchronous operations. Asynchronous operations are performed in the background, so the client does not have to wait for the response from the server to execute further operations. The control is returned to the application immediately after performing the operation. This increases overall responsiveness of the application.
Since asynchronous operations do not notify upon the failure or success of the operations themselves, NCache provides a callback mechanism which can be registered while making the operation call. These callbacks are triggered upon success or failure of the operation. Hence, callbacks are integral in tracking operations. If callbacks are not specified, operation status will not be notified.
When the client performs any write operation asynchronously, NCache uses a thread pool on the server side to facilitate these operations. In case of any callback registered with asynchronous operations, NCache triggers appropriate events only for interested clients upon operation completion.
Bulk Operations
Bulk operations are designed to achieve enhanced performance as they are executed as a single operation synchronously on the server. Retrieving 100 cache items in a single bulk operation works manifold faster than retrieving them through 100 individual calls. Thus, bulk operations boost performance by decreasing network trips to remote server. Bulk operations can be used in scenarios where an application can fetch appropriate Product information in bulk at the start, or insert a query result as a bulk into the cache.
Although a bulk operation is executed as a single operation, the failure of operations is treated individually. For example, if a bulk of 100 items is added to the cache and 20 of those items already exist in the cache, the remaining 80 items will be added to the cache. The existing 20 items will be returned to the application as a dictionary of failed operations.
In This Section
Topology-Wise Behavior of Basic Operations
Provides conceptual detail about how bulk and async operations behave for different cache topologies.
Add Data to Cache
Explains how to add data into cache.
Update Data in Cache
Explains how to update data existing in cache.
Retrieve Data from Cache
Explains how to retrieve data from cache.
Remove Data from Cache
Explains how to remove data from cache.
Emptying the Cache
Explains how to clear a cache.