Hi,
I am working on an application where we use caching extensively. I have a small problem with the caching part. I am trying to use SQLCacheDependency on my cache objects. To give you a brief, we cache the items groupwise based on projects. So i will have more than one cache object for a particular group and likewise for other groups. My requirement is that, if i edit one particular group, i would want to clear the cache items of only that group. When i tried implementing SQLCacheDependency, i was getting the following error
An attempt was made to reference a "CacheDependency object from more than one Cache entry". I am working on creating a file based dependency, but if theres something that can be done to make the SQLCacheDependency, it would be great. I am also attaching the code snippet for the same.
Code:using (SqlConnection cn = new SqlConnection(m_ConnectionString))
{
m_CommandString = " < Query > ";
cn.Open();
using (SqlCommand cm = new SqlCommand(m_CommandString, cn))
{
SqlCacheDependency dep = new SqlCacheDependency(cm);
SqlDataAdapter da = new SqlDataAdapter(cm);
DataTable dt1 = new DataTable();
DataTable dt2 = new DataTable();
da.Fill(dt1);da.Fill(dt2);
Cache.Insert("Group 1", dt1, dep);
Cache.Insert("Group 2", dt2, dep); // I get the error in this line
}
}
Thanks in advance