Method Invoke
Invoke(String, IEntryProcessor, DSReadOption, String, DSWriteOption, String, Object[])
Execution of entry processer regardless of caching topology used, allows to execute code against a cache entry on server side without fetching any data on client side.
Declaration
[TargetMethod(1)]
public object Invoke(string key, IEntryProcessor entryProcessor, DSReadOption dsReadOption = DSReadOption.None, string readProviderName = "default", DSWriteOption dsWriteOption = DSWriteOption.None, string writeProviderName = "default", params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String | key | Key of Cache entry on which the EntryProcessor is executed. |
IEntryProcessor | entryProcessor | IEntryProcessor instance |
DSReadOption | dsReadOption | Readthru option, none if not provided explicity |
System.String | readProviderName | Readthru provider name, default if not provided explicity |
DSWriteOption | dsWriteOption | Writethru option, none if not provided explicity |
System.String | writeProviderName | Writethru provider name, default if not provided explicity |
System.Object[] | arguments | Arguments list for the process. |
Returns
Type | Description |
---|---|
System.Object | Returns an instance of IEntryProcessorResult. |
Examples
Argumetns is optional. Also exception can be thrown explicitily 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[])
Execution of entry processer 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
[TargetMethod(2)]
public virtual ICollection Invoke(string[] keys, IEntryProcessor entryProcessor, DSReadOption dsReadOption = DSReadOption.None, string readProviderName = "default", DSWriteOption dsWriteOption = DSWriteOption.None, string writeProviderName = "default", params object[] arguments)
Parameters
Type | Name | Description |
---|---|---|
System.String[] | keys | Set of keys of Cache entries on which EntryProcessor will be executed. |
IEntryProcessor | entryProcessor |
|
DSReadOption | dsReadOption | Readthru option, none if not provided explicity |
System.String | readProviderName | Readthru provider name, default if not provided explicity |
DSWriteOption | dsWriteOption | Writethru option, none if not provided explicity |
System.String | writeProviderName | Writethru provider name, default if not provided explicity |
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;
}
}