Working of Entry Processor in Cache
This feature is only available in NCache Enterprise.
The Entry Processor has been introduced in NCache to allow users to execute their code (invokable functions) against a set of cache entries on the server side. NCache fully supports the precise execution of the 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 is to fetch the element to be modified, and the second is 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 the case of partitioned topologies, entries are processed on the same node where they reside. It is recommended to use the ‘Object’ data format to avoid deserialization costs every time an entry is processed.
How does the 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 want to process your cache data on the server side.
Once you invoke your Entry Processor to be executed on the server side, the data is processed according to user-specified logic on the server side. Using Entry Processor, you do not have to worry about concurrency as it allows the user to apply a low-level lock on the cache entries it is processing. In case the required entry is locked by the client before executing the entry processor, EntryProcessor provides an option to ignore the lock and access it.
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 are 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 that you implement and the resultant values are Serializable before any operation takes place.