Wednesday, March 18, 2009

Dependency Caching Using Oracle 11g

Dependency Caching.

It is nothing but a one of the caching mechanism for interacting with the Database.

If any data changes happen in the database,

it will find out and full out the data only on that time. It wont go every time to

the database. In this am going to explain how to do dependency caching using Oracle

11g.Also this option not avilable earlier version of oracle 11g.


Example:

In oracle11 g, there is a method called OracleDependency using this have to achieve the Oracle dependency caching.

public DataSet GetTechnicianDrpdwnval()
{
try
{
DataSet DSTechSumDrp = new DataSet();
ltdConn = new OracleConnection();
ltdConn.ConnectionString = ltdConnString;
ltdCommand = new OracleCommand("USP_GetTechSumDropdown", ltdConn);
ltdCommand.CommandType = CommandType.StoredProcedure;
ltdCommand.Parameters.Add(new OracleParameter("Drp_Primaryduty", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
ltdCommand.Parameters.Add(new OracleParameter("Drp_TypeOfWork", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
ltdCommand.Parameters.Add(new OracleParameter("Drp_DispatchCenter", OracleDbType.RefCursor)).Direction = ParameterDirection.Output;
///////////////////////////////Oracle Dependency Caching////////////////////////////////
objOracleDependency = new OracleDependency(ltdCommand);
ltdCommand.Notification.IsNotifiedOnce = false;
objOracleDependency.OnChange += new OnChangeEventHandler(ObjTechDrpDwnval);
///////////////////////////////End/////////////////////////////////////////////////////
ltdDataAdapter = new OracleDataAdapter(ltdCommand);
ltdDataAdapter.Fill(DSTechSumDrp);
return DSTechSumDrp;
}
catch (Exception)
{
throw;
}


public static void OnDatabaseNotificationForGetTechnicianDrpdwnval(object src, OracleNotificationEventArgs args)
{
// Here we have invalidate our cache object if result set changed in database.
InvalidateCache("WireCenter");
}

public static void InvalidateCache(String CacheName)
{
if (HttpRuntime.Cache[CacheName] != null)
{
HttpRuntime.Cache.Remove(CacheName);
}
}