The Entry Processor has been introduced in NCache to allow users to execute their code (invocable functions) against a set of cache entries on the server side. NCache fully supports precise execution of Entry Processor regardless of the caching topology being used.
In the usual update scenario, you actually make two network trips to and from the cache. One, to fetch the element to be modified, and the second to save the updated value back into the cache. This is where Entry Processors come in handy: you can modify cache entries on the server side without involving these entries to travel over the network for fetch and update operations. This results in fairly noticeable performance improvement because of the avoidance of network trips and unnecessary consumption of resources.
In case of partitioned topologies, entries are processed on the same node where they reside. It is recommended to use ‘Object’ data format to avoid deserialization cost every time an entry is processed.
How does Entry Processor work?
Entry Processor can be executed on a single cache entry or a set of cache entries. It is particularly useful if you are to perform bulk processing over your items.
Once you invoke your
EntryProcessor to be executed on the server side, the
data is modified accordingly in the cache server. Using Entry Processor, you do
not have to worry about concurrency as it applies a low-level lock on the cache
items it is processing. In case the required entry is locked by the client,
EntryProcessor can ignore the lock and access it.
This feature has just one component- the EntryProcessor.
This component contains the actual implementation of the code you want to be executed against the cache entries. Make sure that the class you implement is Serializable, along with any parameters the process code might be taking in.
Entry Processors work in parallel across the cluster, on the nodes that contain the entries. This helps in reducing a significant amount of network burden as the extra trips of fetching data to execute the code and saving it back to the cache is eliminated.
The values may be changed or removed and it is up to you how you treat the resultant data:
Fetch the data without saving the change in the cache and use it in your application locally.
Save the modification in the cache.
Update the modification in both the cache and data source through ReadThru and WriteThru operations.
Make sure that the
EntryProcessor class which you implement and the resultant
values are Serializable before any operation takes place.
In This Section
Sample Implementation of IEntryProcessor Interface
Gives an example of how the IEntryProcessor Interface can be implemented.
Sample Usage of IEntryProcessor
Gives an example on the usage of the Entry Processor in your code.