Click here to Skip to main content
15,915,750 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I am new to implement caching. Please help me..
I have a UI page with different search inputs and based on different input i have to store the date table in cache and return the data from cache. I have to use the cache object in my paging and sorting results.
Even if change the ID values, it is returning data from the same cache object..
Below is my code:
C#
private DataTable GetAuditResults()
       {
           if (Cache["AuditResults"] != null)
              return (DataTable)Cache["AuditResults"];
           string connectionString = WebConfigurationManager.ConnectionStrings["OracleDbCon"].ConnectionString;
           using (OracleConnection con = new OracleConnection(connectionString))
           {
               con.Open();
               OracleCommand cmd = new OracleCommand();
               cmd.Connection = con;
               cmd.CommandType = CommandType.StoredProcedure;
               cmd.CommandText = "blah blah blah";
               cmd.Parameters.Add(new OracleParameter("P_ID", Id)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_LISTOFSAPSALESORDERNO", salesId)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_SAPIDOCNUMBER", idocId)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_REFERENCEID", refId)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_STARTDATE", fromDate)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_ENDDATE", toDate)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_MESSAGE", messageType)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_STATUS", status)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add(new OracleParameter("P_SAPSHIPLOC", shipLoc)).Direction = ParameterDirection.Input;
               cmd.Parameters.Add("C_SELECT", OracleType.Cursor).Direction = ParameterDirection.Output;
               OracleDataAdapter adapter = new OracleDataAdapter(cmd);
               DataSet ds = new DataSet();
               adapter.Fill(ds);
               if (con.State == ConnectionState.Open)
                   con.Close();
       //Caching
               Cache["ID"] = Id;
               string[] dependencyKey = new string[] { "ID" };
               Cache.Add("AuditResults", ds.Tables[0], new CacheDependency(new string[] { },dependencyKey), DateTime.Now.AddHours(1), TimeSpan.Zero, CacheItemPriority.High, null);
               return ds.Tables[0];
           }
       }
Posted
Updated 26-Sep-11 5:21am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900