|
Enabling Notifications For DB2
NOTE: This feature is not available in NCache Express and Professional edition.
For enabling notifications for DB2 tables, you need to follow these steps:
-
Create a table 'ncache_db_sync' having four fields (cache_key VARCHAR2, cache_id VARCHAR2, modified NUMBER and work_in_progress NUMBER). Script to create the table is as follows:
//Create table'ncache_db_sync'
CREATE TABLE ncache_db_sync(
cache_key VARCHAR(256),
cache_id VARCHAR(256),
modified BIT DEFAULT(0),
work_in_progress BIT DEFAULT(0),
PRIMARY KEY(cache_key, cache_id));
-
Create UPDATE and DELETE triggers, for every table on which notification is required. They set the 'modified' field of corresponding row in the ncache_db_sync table to 1. To carry out the task, see the following sample script that creates trigger on 'Products' table:
//create triggers
CREATE TRIGGER myUpdateTrigger
AFTER UPDATE ON Products
REFERENCING OLD AS o
FOR EACH ROW
UPDATE ncache_db_sync
SET modified = 1
WHERE cache_key = (:o.ProductID || ':Products');
CREATE TRIGGER myDeleteTrigger
AFTER DELETE ON Products
REFERENCING OLD AS o
FOR EACH ROW
UPDATE ncache_db_sync
SET modified = 1
WHERE cache_key = (:o.ProductID || ':Products');
Note: cache_key must be the same key that is used to add the corresponding record in the cache.
-
Sets the work_in_progress flag for those rows where modified flag is set. And fetches all those rows.
-
Removes all keys from the cache as they all have expired now.
-
After successfully removing all keys from the cache, all those rows where work_in_progress flag is set are removed from the 'ncache_db_sync' table.
If a node crashes while it was removing items from the cache, the next node in the cluster will start process from step one.
See Also
|
|