Alachisoft NCache 4.1 - Online Documentation

ChangeMonitor

 
NCache provides its own implementation for ChanageMonitor class and does not support .net implementation for the same class. ChangeMonitor class is used as a base class for derived monitor classes that are specialized for particular cache implementations. These classes monitor the changes in the state of the data on which cache items depends to keep the cache items valid. Following are the different Change Monitors (file based, key based, database dependency) provided by NCache for managing cache dependencies.
 
NCacheEntryChangeMonitor Class:
 
This class represents an object that monitors changes to an entry. Entry based dependency associates one cached item with another item in the cache. It invalidates the dependent item when that particular item changes. Whenever that item is removed or updated from the cache, associated object will be expired. Entry based dependency is cascaded.
The following steps demonstrate how to use NCacheEntryChangeMonitor class.
 
string [] depKeys = ("key1", "key2", "key3"};
NCacheEntryChangeMonitor changeMonitor = new NCacheEntryChangeMonitor(depKeys);
ciPolicy = new CacheItemPolicy();
ciPolicy.ChangeMonitors.Add(changeMonitor);
_cache.Add(cItem, ciPolicy);
_cache.Add("Test key", "Key Value", CacheItemPolicy);
 
NCacheFileChangeMonitor Class:
 
This class represents an object that monitors changes to files. It sets the validity of the cache item based on an external file or files. When this resource changes, the cached object becomes obsolete and is removed from the cache. In this class a File/Directory path is provided. Cache object also expires if the path is used to create a new File/Directory.
The following steps demonstrate how to use NCacheFileChangeMonitor class.
 
string [] depFile = { "c:\NCache\file1.txt", "c:\NCache\file2.txt" };
NCacheFileChangeMonitor changeMonitor = new NCacheFileChangeMonitor(fileNames);
ciPolicy = new CacheItemPolicy();
ciPolicy.ChangeMonitors.Add(changeMonitor);
_cache.Add(cItem, ciPolicy);
_cache.Add("Test key", "Key Value", CacheItemPolicy);
 
NCacheSqlChangeMonitor Class:
 
This class provides change monitoring for SQL Server databases and cannot be inherited. While working with databases in a multiuser environment, updates in the databases are very frequent. NCacheSqlChangeMonitor sets the validity of the cache item based on database. In this case item expires if result of the command (based on command text) changes.
The following steps demonstrate how to use NCacheSqlChangeMonitor class.
 
string conString = @"Server=TEST7; Initial catalog=Northwind; User ID=sa; password= myPassword;" ;
string cmdString = "SELECT ProductID FROM dbo.products WHERE ProductID = 10" ;
NCacheSqlChangeMonitor changeMonitor = new NCacheSqlChangeMonitor(conString, cmdString);
ciPolicy = new CacheItemPolicy();
ciPolicy.ChangeMonitors.Add(changeMonitor);
_cache.Add(cItem, ciPolicy);
_cache.Add( "Test key" , "Key Value" , CacheItemPolicy);
 
NCacheOracleChangeMonitor Class:
 
This class provides change monitoring for Oracle Server databases. This class cannot be inherited. While working with databases in a multiuser environment, updates in the databases are very frequent. NCacheOracleChangeMonitor sets the validity of the cache item based on database. In this case item expires if result of the command (based on command text) changes.
The following steps demonstrate how to use NCacheOracleChangeMonitor class.
 
string conString = "Data Source = TORCL; User Id = myUsername; Password = myPassword" ;
string cmdString = "SELECT ProductID FROM dbo.products WHERE ProductID = 10" ;
NCacheOracleChangeMonitor changeMonitor = new NCacheOracleChangeMonitor(conString, cmdString);
ciPolicy = new CacheItemPolicy();
ciPolicy.ChangeMonitors.Add(changeMonitor);
_cache.Add(cItem, ciPolicy);
_cache.Add("Test key", "Key Value", CacheItemPolicy);
 
 
See Also
 
Copyright © 2005-2012 Alachisoft. All rights reserved.