Basic Operations for Caching Data
NCache provides various CRUD APIs for caching data. You can then perform operations on the data in cache. 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.
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.
This feature is only available in NCache Enterprise Edition.
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's asynchronous calls return an object of the Task class which can further be used to get the status of the operation.
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 for Cache 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 Existing Data in Cache
Explains how to update data existing in cache.
Retrieve Existing Cache Data
Explains how to retrieve data from cache.
Remove Data from Cache
Explains how to remove data from cache.
Clear Cache Data
Explains how to clear a cache.