|Configuring the Native Client Cache / Region Entries|
For native client regions, you can programmatically register interest in entry keys stored on a cache server region. A client region receives update notifications from the cache server for the keys of interest.
You can register interest for specific entry keys or for all keys. Regular expressions can be used to register interest for keys whose strings match the expression. You can also unregister interest for specific keys, groups of keys based on regular expressions, or for all keys.
You register client interest through the C++ or NET API. The C++ API provides the registerKeys, registerAllKeys, and registerRegex methods, with corresponding unregistration accomplished using the unregisterKeys, unregisterAllKeys, and unregisterRegex methods. The .NET API provides the RegisterKeys, RegisterAllKeys, and RegisterRegex methods, with corresponding unregistration accomplished using the UnregisterKeys, UnregisterAllKeys, and UnregisterRegex methods.
The registerKeys, registerRegex and registerAllKeys methods have the option to populate the cache with the registration results from the server. The registerRegex and registerAllKeys methods can also optionally return the current list of keys registered on the server.
In addition to the programmatic function calls, to register interest for a server region and receive updated entries you need to configure the region with the PROXY or CACHING_PROXY RegionShortcut setting. The region's pool should have subscription-enabled=true set either in the client XML or programmatically via a CacheFactory::setSubscriptionEnabled(true) API call. Otherwise, when you register interest, you will get an UnsupportedOperationException.
<region name = "listenerWriterLoader" refid="CACHING_PROXY"> ...
Both native clients and Java clients that have subscriptions enabled track and drop (ignore) any duplicate notifications received. To reduce resource usage, a client expires tracked sources for which new notifications have not been received for a configurable amount of time.
Notifications invoke CacheListeners of cacheless clients in all cases for keys that have been registered on the server. Similarly, invalidates received from the server invoke CacheListeners of cacheless clients.
If you register to receive notifications, listener callbacks are invoked irrespective of whether the key is in the client cache when a destroy or invalidate event is received.
keys0.push_back(keyPtr1); keys1.push_back(keyPtr3); regPtr0->registerKeys(keys0); regPtr1->registerKeys(keys1);
The registerRegex function registers interest in a regular expression pattern. The server automatically sends the client changes for entries whose keys match the specified pattern.
Keys must be strings in order to register interest using regular expressions.
In this register interest scenario, a cache listener is used with a cacheless region that has subscription-enabled set to true. The client region is configured with caching disabled; client notification is enabled; and a cache listener is established. The client has not registered interest in any keys:
When a value changes in another client, it sends the event to the server. The server will not send the event to the cacheless client, even though client-notification is set to true.
To activate the cache listener so the cacheless region receives updates, the client should explicitly register interest in some or all keys by using one of the API calls for registering interest. This way, the client receives all events for the keys to which it has registered interest. This applies to Java-based clients as well as native clients.