NCache 4.6 - Online Documentation

Sample Usage of EntryProcessor

 To execute your code on the server side of the cache, you need to call the Invoke() method in NCache.
This method returns an instance of the IEntryProcessorResult for a single entry, and a ICollection of IEntryProcessorResult for a set of cache entries.
It takes in multiple overloaded parameters:
·     Key or key[] of the cache entry
·     IEntryProcessor instance
·     Read-Through Provider name if you want to fetch the change
·     Read Option (None, ReadThru)
·     Write-Through Provider name if you want the updated change to be saved in the cache and data source
·     Write Option (None, WriteThru, WriteBehind)
·     List of arguments to be passed to the process
The IEntryProcessorResult instance implements the following methods which aid you in using the result accordingly:
Cache entry on which the EntryProcessor is executed.
Resultant value after execution.
Flag to indicate operation success. If it returns false, the user can create their own logic to handle the EntryProcessorException thrown.
Exception Handling
If any exception is thrown by the EntryProcessor, it is wrapped in an EntryProcessorException. If this occurs, no mutations will be made to the cache.
Moreover, users can also specify in their logic the cases where they would want the exception to be thrown.
The following example gets a new instance of CustomEntryProcessor implementing EntryProcessor interface, and then invokes the Entry Processor on items accordingly.
       To utilize the API, include the following namespace in your application: Alachisoft.NCache.Web.Caching. 
                //Get a new instance of sample Class implementing EntryProcessor interface.
                CustomEntryProcessor myProcessor = new CustomEntryProcessor();
                string[] keys = new string[] { "1", "5", "12", "15" };
                _cache.Insert(keys[0], "Value1");
                _cache.Insert(keys[1], "Value1");
                _cache.Insert(keys[2], "Value1");
                _cache.Insert(keys[3], "Value1");
                //Invoking the Entry processor on a single item.
                Object invokerVal = _cache.Invoke("1", myProcessor);
                //Invoking the Entry processor against a single item.
                invokerVal = _cache.Invoke("15", myProcessor);
                //Invoking the Entry processor against a set of items.
                ICollection retEntries = _cache.Invoke(keys, myProcessor);
            catch (Exception ex)
                //handle exception
See Also