Sample Usage of Entry Processor
To execute your code on the server side of the cache, you need to call the
Invoke()
method.
Method | Description |
---|---|
Invoke() |
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 entryIEntryProcessor instanceReadThru Provider name if you want to fetch the changeNone , ReadThru )WriteThru Provider name if you want the updated change to be saved in the cache and data sourceNone, WriteThru, WriteBehind ) |
The IEntryProcessorResult
instance implements the following methods which aid
you in using the result accordingly:
Member | Description |
---|---|
Key |
Cache entry on which the EntryProcessor is executed. |
Value |
Resultant value after execution. |
IsSuccessful |
Flag to indicate operation success. If it returns false, the user can create their own logic to handle the EntryProcessorException thrown. |
Exception |
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. |
try
{
//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
Sample Implementation of IEntryProcessor Interface