Method Invoke
Invoke(String, IEntryProcessor, Object[])
Execution of entry processor regardless of caching topology used, allows to execute code against a cache entry on server side without fetching any data on client side.
Declaration
public object Invoke(string key, IEntryProcessor entryProcessor, params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key of Cache entry on which the EntryProcessor is executed. |
IEntryProcessor | entryProcessor | IEntryProcessor instance |
System.Object[] | arguments | Arguments list for the process. |
Returns
Type | Description |
---|---|
System.Object | Returns an instance of IEntryProcessorResult. |
Examples
Arguments is optional. Also exception can be thrown explicitly by specifying such cases while implementing IEntryProcessor interface.
Cache _cache= NCache.InitializeCache("myCache");
//Get a new instance of sample Class implementing EntryProcessor interface.
CustomEntryProcessor myProcessor = new CustomEntryProcessor();
_cache.Insert("1", "Value1");
_cache.Insert("2", "Value2");
_cache.Insert("15", "Value3");
//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);
//Implementation of IEntryProcesser Interface
public class CustomEntryProcessor : IEntryProcessor
{
public bool IgnoreLock()
{
return true;
}
public object ProcessEntry(IMutableEntry entry, params object[] arguments)
{
if (entry.Key.Equals("1"))
{
if (entry.Exists())
{
entry.Remove();
return 0;
}
else
{
entry.Remove();
return -1;
}
}
else if (entry.Equals("15"))
{
object value = "Greater Than 10";
entry.Value = value;
return value;
}
return 1;
}
}
Invoke(String, IEntryProcessor, DSReadOption, String, DSWriteOption, String, Object[])
Declaration
public object Invoke(string key, IEntryProcessor entryProcessor, DSReadOption dsReadOption, string readProviderName, DSWriteOption dsWriteOption, string writeProviderName, params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | |
IEntryProcessor | entryProcessor | |
DSReadOption | dsReadOption | |
System.String | readProviderName | |
DSWriteOption | dsWriteOption | |
System.String | writeProviderName | |
System.Object[] | arguments |
Returns
Type | Description |
---|---|
System.Object |
Invoke(String[], IEntryProcessor, Object[])
Execution of entry processor on a set of keys regardless of caching topology used, allows to execute code against a set of cache entries on server side without fetching any data on client side.
Declaration
public ICollection Invoke(string[] keys, IEntryProcessor entryProcessor, params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | Set of keys of Cache entries on which EntryProcessor will be executed. |
IEntryProcessor | entryProcessor |
|
System.Object[] | arguments | Arguments list for the process. |
Returns
Type | Description |
---|---|
System.Collections.ICollection | Returns a collection of instances of IEntryProcessorResult. |
Examples
Cache _cache= NCache.InitializeCache("myCache");
//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 against a set of items.
ICollection retEntries = _cache.Invoke(keys, myProcessor);
//Implementation of IEntryProcesser Interface
public class CustomEntryProcessor : IEntryProcessor
{
public bool IgnoreLock()
{
return true;
}
public object ProcessEntry(IMutableEntry entry, params object[] arguments)
{
if (entry.Key.Equals("1"))
{
if (entry.Exists())
{
entry.Remove();
return 0;
}
else
{
entry.Remove();
return -1;
}
}
else if (entry.Equals("15"))
{
object value = "Greater Than 10";
entry.Value = value;
return value;
}
return 1;
}
}
Invoke(String[], IEntryProcessor, DSReadOption, String, DSWriteOption, String, Object[])
Declaration
public ICollection Invoke(string[] keys, IEntryProcessor entryProcessor, DSReadOption dsReadOption, string readProviderName, DSWriteOption dsWriteOption, string writeProviderName, params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | |
IEntryProcessor | entryProcessor | |
DSReadOption | dsReadOption | |
System.String | readProviderName | |
DSWriteOption | dsWriteOption | |
System.String | writeProviderName | |
System.Object[] | arguments |
Returns
Type | Description |
---|---|
System.Collections.ICollection |