NCache 4.6 - Online Documentation

Sample Implementation of IEntryProcessor Interface

 
Implement the interface IEntryProcessor  in NCache 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.
IMutableEntry implements the following methods and flags:
The class implementing the IMutableEntry is NCacheMutableEntry, which provides the following flags:
·     IsAvailableInCache
·     IsUpdated
·     IsRemoved
For example, if the entry is updated in the method and you wish to save the mutated value in the cache, you can initialize Value() with the new value. Else, if you only wish to get the result and not update it, you should not tamper with the IMutableEntry flags.
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 EntryProcessor 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.
 
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;
        }
    }
 
 
See Also