Sample Implementation of IEntryProcessor Interface
Implement the interface IEntryProcessor
and provide implementation for
ProcessEntry()
method.
Member | Description |
---|---|
ProcessEntry(IMutableEntry, params []) |
This method will contain the logic to be executed over the cache item(s) on the server side. It takes in an instance of IMutableEntry and an array of parameters. The class implementing the IMutableEntry is NCacheMutableEntry , which provides the following flags:For example, if the entry is updated in the method and you wish to save the mutated value in the cache, you can initialize |
IgnoreLock() |
In case an entry is locked by an application and you wish to run the EntryProcessor over it, you can use this method to ignore the lock and access the entry to execute your method. |
The following example implements the IEntryProcessor
interface in
CustomEntryProcessor
class, the keys of entries in the cache are assumed to be
of integer (int) type in .NET.
To utilize the
IEntryProcessor
interface, include the following namespace in your application:Alachisoft.NCache.Runtime.Processor.EntryProcessor.
[Serializable]
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 v = "Greater Than 10";
entry.Value = v;
return v;
}
return 1;
}
}
See Also
Sample Usage of Entry Processor