NCache 4.6 - Online Documentation

Using Oracle Dependency

Oracle Dependency is provided by NCache for synchronizing cache with Oracle database. Item expires if result of the command (based on command text) changes. Oracle Dependency is only available for Oracle database 10g release 2 or later. Also make sure that Oracle Data Providers for .NET (version or later) is installed.
1. Configuring Notification on Oracle server 
NCache tracks changes in database using notifications received from Oracle server. For this purpose NCache registers Change Notification with oracle server. NCache server should have Change Notification privileges to create notification registration. Grants the Change Notification privilege to the user by following statement.
"grant change notification to scott"
2. Adding Data with Oracle Dependency
Following code shows how to add data with Oracle Dependency. Altering data after addition with Oracle Dependency will remove it from cache.
      To utilize the API, include the following namespace in your application: Alachisoft.NCache.Runtime.Dependencies.
            //Create object to be added with dependency
            Product product = new Product();
            product.ProductID = 1001;
            product.ProductName = "Chai";
            string key = "Product:" + product.ProductID;
            {   //Creating OracleCacheDependency
                String connectionString = "User Id=scott;Password=tiger;Data Source=oracle";
                string query = "SELECT rowID, productID FROM dbo.Products WHERE productID = 1001";
                OracleCacheDependency oracleDependency = new OracleCacheDependency(connectionString, query);
                //Adding cache item "Product:1001" with SqlDependency
                cache.Insert(key, product, oracleDependency, Cache.NoAbsoluteExpiration, Cache.NoSlidingExpiration,                                    CacheItemPriority.Normal);
                //Modify Product record in database while program waits...
                //... and then check for its existence
                Object item = cache.Get(key);
                if (item == null)
                    //item removed successfully
                    //Oracle dependency did not work
            catch (OperationFailedException e)
                //handle exception
In Oracle 10g, database change notifications are only object based. This means that change notifications will be fired if any row is modified in object. Therefore rowID needs to be checked to confirm if the row changed is the one for which the event is registered. RowIDs cannot be retrieved unless explicitly included in query. Therefore customer has to include rowID in query that they are registering with OracleDependecy, otherwise change notification will be fired if any row is modified in table.
When rowID is included in query like "select rowID, productID, productname, unitprice from Products where ProductID = 220", NCache will save the rowID of rows for which change notification is registered. When it receives any change notification, NCache will compare the rowIDs to determine whether the row changed is the one for which the rowID is registered. Otherwise NCache will have no way to check this and items for which change notification is registered will be removed after any row in table changes.
In Oracle 11g, both object based and query based (default) notifications are provided. In query based notifications; change of the modified row will be notified only if the change notification is registered for it.
See Also