[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Ravi

1/23/2008 9:18:00 AM

Hi,
Am using SqlDependecy for ASP.Net cache. The sql databse is enabled for
notifications. I have added the SqlDependency.Start in my application_start.
I have a command object which retrives values from table based in a filter
condition. I have two cache object depending on this command object. After
the first object (i.e T1) is added to cache when the control executes the
cache.insert for adding T2 , T1 is removed from Cache. Is this expected
behaviour?

I have added sample code for reference,


SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandText = "dbo.GetAllTasks";
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
cmd.Parameters["@TNAME"].Value = "T1";
cmd.Prepare();
System.Web.Caching.CacheDependency sqldependency = new
System.Web.Caching.SqlCacheDependency(cmd);

SqlDataAdapter da = new SqlDataAdapter(cmd);

DataSet ds = new DataSet();
da.Fill(ds);

HttpContext.Current.Cache.Add("T1", "hello", sqldependency,
System.Web.Caching.Cache.NoAbsoluteExpiration,
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);

SqlCommand cmd1 = new SqlCommand();
cmd1.Connection = con;
cmd1.CommandText = "dbo.GetAllTasks";
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
cmd1.Parameters["@TNAME"].Value = "T2";
cmd1.Prepare();
System.Web.Caching.CacheDependency sqldependency1 = new
System.Web.Caching.SqlCacheDependency(cmd1);
SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
DataSet ds1 = new DataSet();
da1.Fill(ds1);
HttpContext.Current.Cache.Add("T3", "test", sqldependency1,
System.Web.Caching.Cache.NoAbsoluteExpiration,
System.Web.Caching.Cache.NoSlidingExpiration,
System.Web.Caching.CacheItemPriority.Normal, null);

7 Answers

Alvin Bruney [ASP.NET MVP]

1/24/2008 1:46:00 AM

0

This is by design, the cache scavenging mechanism is overly aggressive in
..NET+

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------



"Ravi" <Ravi@discussions.microsoft.com> wrote in message
news:E379D674-BD6D-4D09-A0DA-8616F1FB1965@microsoft.com...
> Hi,
> Am using SqlDependecy for ASP.Net cache. The sql databse is enabled for
> notifications. I have added the SqlDependency.Start in my
> application_start.
> I have a command object which retrives values from table based in a filter
> condition. I have two cache object depending on this command object. After
> the first object (i.e T1) is added to cache when the control executes the
> cache.insert for adding T2 , T1 is removed from Cache. Is this expected
> behaviour?
>
> I have added sample code for reference,
>
>
> SqlCommand cmd = new SqlCommand();
> cmd.Connection = con;
> cmd.CommandText = "dbo.GetAllTasks";
> cmd.CommandType = CommandType.StoredProcedure;
> cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> cmd.Parameters["@TNAME"].Value = "T1";
> cmd.Prepare();
> System.Web.Caching.CacheDependency sqldependency = new
> System.Web.Caching.SqlCacheDependency(cmd);
>
> SqlDataAdapter da = new SqlDataAdapter(cmd);
>
> DataSet ds = new DataSet();
> da.Fill(ds);
>
> HttpContext.Current.Cache.Add("T1", "hello", sqldependency,
> System.Web.Caching.Cache.NoAbsoluteExpiration,
> System.Web.Caching.Cache.NoSlidingExpiration,
> System.Web.Caching.CacheItemPriority.Normal, null);
>
> SqlCommand cmd1 = new SqlCommand();
> cmd1.Connection = con;
> cmd1.CommandText = "dbo.GetAllTasks";
> cmd1.CommandType = CommandType.StoredProcedure;
> cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> cmd1.Parameters["@TNAME"].Value = "T2";
> cmd1.Prepare();
> System.Web.Caching.CacheDependency sqldependency1 = new
> System.Web.Caching.SqlCacheDependency(cmd1);
> SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
> DataSet ds1 = new DataSet();
> da1.Fill(ds1);
> HttpContext.Current.Cache.Add("T3", "test", sqldependency1,
> System.Web.Caching.Cache.NoAbsoluteExpiration,
> System.Web.Caching.Cache.NoSlidingExpiration,
> System.Web.Caching.CacheItemPriority.Normal, null);
>

Ravi

1/25/2008 6:48:00 AM

0

Hi Alvin,
Does this mean we cannot add two object in cache having same sql
dependency?

Thanks,
Ravi

"Alvin Bruney [ASP.NET MVP]" wrote:

> This is by design, the cache scavenging mechanism is overly aggressive in
> .NET+
>
> --
>
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The O.W.C. Black Book, 2nd Edition
> Exclusively on www.lulu.com/owc $19.99
> -------------------------------------------------------
>
>
>
> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
> news:E379D674-BD6D-4D09-A0DA-8616F1FB1965@microsoft.com...
> > Hi,
> > Am using SqlDependecy for ASP.Net cache. The sql databse is enabled for
> > notifications. I have added the SqlDependency.Start in my
> > application_start.
> > I have a command object which retrives values from table based in a filter
> > condition. I have two cache object depending on this command object. After
> > the first object (i.e T1) is added to cache when the control executes the
> > cache.insert for adding T2 , T1 is removed from Cache. Is this expected
> > behaviour?
> >
> > I have added sample code for reference,
> >
> >
> > SqlCommand cmd = new SqlCommand();
> > cmd.Connection = con;
> > cmd.CommandText = "dbo.GetAllTasks";
> > cmd.CommandType = CommandType.StoredProcedure;
> > cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> > cmd.Parameters["@TNAME"].Value = "T1";
> > cmd.Prepare();
> > System.Web.Caching.CacheDependency sqldependency = new
> > System.Web.Caching.SqlCacheDependency(cmd);
> >
> > SqlDataAdapter da = new SqlDataAdapter(cmd);
> >
> > DataSet ds = new DataSet();
> > da.Fill(ds);
> >
> > HttpContext.Current.Cache.Add("T1", "hello", sqldependency,
> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> > System.Web.Caching.Cache.NoSlidingExpiration,
> > System.Web.Caching.CacheItemPriority.Normal, null);
> >
> > SqlCommand cmd1 = new SqlCommand();
> > cmd1.Connection = con;
> > cmd1.CommandText = "dbo.GetAllTasks";
> > cmd1.CommandType = CommandType.StoredProcedure;
> > cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> > cmd1.Parameters["@TNAME"].Value = "T2";
> > cmd1.Prepare();
> > System.Web.Caching.CacheDependency sqldependency1 = new
> > System.Web.Caching.SqlCacheDependency(cmd1);
> > SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
> > DataSet ds1 = new DataSet();
> > da1.Fill(ds1);
> > HttpContext.Current.Cache.Add("T3", "test", sqldependency1,
> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> > System.Web.Caching.Cache.NoSlidingExpiration,
> > System.Web.Caching.CacheItemPriority.Normal, null);
> >
>

Alvin Bruney [ASP.NET MVP]

1/27/2008 3:42:00 PM

0

I can't be certain that the cache eviction is because of the other insert.
You perhaps need to explain a bit more. Typically this isn't an issue and
you should be able to have multiple dependencies.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------



"Ravi" <Ravi@discussions.microsoft.com> wrote in message
news:21FE9A7A-B207-4DAB-821E-E95D1E5C6FC2@microsoft.com...
> Hi Alvin,
> Does this mean we cannot add two object in cache having same sql
> dependency?
>
> Thanks,
> Ravi
>
> "Alvin Bruney [ASP.NET MVP]" wrote:
>
>> This is by design, the cache scavenging mechanism is overly aggressive in
>> .NET+
>>
>> --
>>
>> Regards,
>> Alvin Bruney [MVP ASP.NET]
>>
>> [Shameless Author plug]
>> The O.W.C. Black Book, 2nd Edition
>> Exclusively on www.lulu.com/owc $19.99
>> -------------------------------------------------------
>>
>>
>>
>> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
>> news:E379D674-BD6D-4D09-A0DA-8616F1FB1965@microsoft.com...
>> > Hi,
>> > Am using SqlDependecy for ASP.Net cache. The sql databse is enabled
>> > for
>> > notifications. I have added the SqlDependency.Start in my
>> > application_start.
>> > I have a command object which retrives values from table based in a
>> > filter
>> > condition. I have two cache object depending on this command object.
>> > After
>> > the first object (i.e T1) is added to cache when the control executes
>> > the
>> > cache.insert for adding T2 , T1 is removed from Cache. Is this expected
>> > behaviour?
>> >
>> > I have added sample code for reference,
>> >
>> >
>> > SqlCommand cmd = new SqlCommand();
>> > cmd.Connection = con;
>> > cmd.CommandText = "dbo.GetAllTasks";
>> > cmd.CommandType = CommandType.StoredProcedure;
>> > cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
>> > cmd.Parameters["@TNAME"].Value = "T1";
>> > cmd.Prepare();
>> > System.Web.Caching.CacheDependency sqldependency = new
>> > System.Web.Caching.SqlCacheDependency(cmd);
>> >
>> > SqlDataAdapter da = new SqlDataAdapter(cmd);
>> >
>> > DataSet ds = new DataSet();
>> > da.Fill(ds);
>> >
>> > HttpContext.Current.Cache.Add("T1", "hello", sqldependency,
>> > System.Web.Caching.Cache.NoAbsoluteExpiration,
>> > System.Web.Caching.Cache.NoSlidingExpiration,
>> > System.Web.Caching.CacheItemPriority.Normal, null);
>> >
>> > SqlCommand cmd1 = new SqlCommand();
>> > cmd1.Connection = con;
>> > cmd1.CommandText = "dbo.GetAllTasks";
>> > cmd1.CommandType = CommandType.StoredProcedure;
>> > cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
>> > cmd1.Parameters["@TNAME"].Value = "T2";
>> > cmd1.Prepare();
>> > System.Web.Caching.CacheDependency sqldependency1 = new
>> > System.Web.Caching.SqlCacheDependency(cmd1);
>> > SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
>> > DataSet ds1 = new DataSet();
>> > da1.Fill(ds1);
>> > HttpContext.Current.Cache.Add("T3", "test", sqldependency1,
>> > System.Web.Caching.Cache.NoAbsoluteExpiration,
>> > System.Web.Caching.Cache.NoSlidingExpiration,
>> > System.Web.Caching.CacheItemPriority.Normal, null);
>> >
>>

Ravi

1/28/2008 7:24:00 AM

0

Hi Alvin,
I have pasted my code in the first post.
Actually, when I step into the code I can see in my Autos widow the Cache
object having a count = 1 and when it executes The next Cache.Add the count
becomes zero 0(Note: I tried doing this using both Cache.Insert and
Cache.Add). Can you please direct me where and what should i look to track
down the problem. I have tested this app with 1 item in cache and it works
perfectly fine and gets invalidated when the corresponding result set
changes. But I am not able to test it for two items because of the above
issue.

Thanks,
Ravi

"Alvin Bruney [ASP.NET MVP]" wrote:

> I can't be certain that the cache eviction is because of the other insert.
> You perhaps need to explain a bit more. Typically this isn't an issue and
> you should be able to have multiple dependencies.
>
> --
>
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The O.W.C. Black Book, 2nd Edition
> Exclusively on www.lulu.com/owc $19.99
> -------------------------------------------------------
>
>
>
> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
> news:21FE9A7A-B207-4DAB-821E-E95D1E5C6FC2@microsoft.com...
> > Hi Alvin,
> > Does this mean we cannot add two object in cache having same sql
> > dependency?
> >
> > Thanks,
> > Ravi
> >
> > "Alvin Bruney [ASP.NET MVP]" wrote:
> >
> >> This is by design, the cache scavenging mechanism is overly aggressive in
> >> .NET+
> >>
> >> --
> >>
> >> Regards,
> >> Alvin Bruney [MVP ASP.NET]
> >>
> >> [Shameless Author plug]
> >> The O.W.C. Black Book, 2nd Edition
> >> Exclusively on www.lulu.com/owc $19.99
> >> -------------------------------------------------------
> >>
> >>
> >>
> >> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
> >> news:E379D674-BD6D-4D09-A0DA-8616F1FB1965@microsoft.com...
> >> > Hi,
> >> > Am using SqlDependecy for ASP.Net cache. The sql databse is enabled
> >> > for
> >> > notifications. I have added the SqlDependency.Start in my
> >> > application_start.
> >> > I have a command object which retrives values from table based in a
> >> > filter
> >> > condition. I have two cache object depending on this command object.
> >> > After
> >> > the first object (i.e T1) is added to cache when the control executes
> >> > the
> >> > cache.insert for adding T2 , T1 is removed from Cache. Is this expected
> >> > behaviour?
> >> >
> >> > I have added sample code for reference,
> >> >
> >> >
> >> > SqlCommand cmd = new SqlCommand();
> >> > cmd.Connection = con;
> >> > cmd.CommandText = "dbo.GetAllTasks";
> >> > cmd.CommandType = CommandType.StoredProcedure;
> >> > cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> >> > cmd.Parameters["@TNAME"].Value = "T1";
> >> > cmd.Prepare();
> >> > System.Web.Caching.CacheDependency sqldependency = new
> >> > System.Web.Caching.SqlCacheDependency(cmd);
> >> >
> >> > SqlDataAdapter da = new SqlDataAdapter(cmd);
> >> >
> >> > DataSet ds = new DataSet();
> >> > da.Fill(ds);
> >> >
> >> > HttpContext.Current.Cache.Add("T1", "hello", sqldependency,
> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> >> > System.Web.Caching.Cache.NoSlidingExpiration,
> >> > System.Web.Caching.CacheItemPriority.Normal, null);
> >> >
> >> > SqlCommand cmd1 = new SqlCommand();
> >> > cmd1.Connection = con;
> >> > cmd1.CommandText = "dbo.GetAllTasks";
> >> > cmd1.CommandType = CommandType.StoredProcedure;
> >> > cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> >> > cmd1.Parameters["@TNAME"].Value = "T2";
> >> > cmd1.Prepare();
> >> > System.Web.Caching.CacheDependency sqldependency1 = new
> >> > System.Web.Caching.SqlCacheDependency(cmd1);
> >> > SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
> >> > DataSet ds1 = new DataSet();
> >> > da1.Fill(ds1);
> >> > HttpContext.Current.Cache.Add("T3", "test", sqldependency1,
> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> >> > System.Web.Caching.Cache.NoSlidingExpiration,
> >> > System.Web.Caching.CacheItemPriority.Normal, null);
> >> >
> >>
>

Alvin Bruney [ASP.NET MVP]

1/28/2008 4:12:00 PM

0

Try this, set the cache experiation to nonremove a la
System.Web.Caching.CacheItemPriority.Normal
That should prevent evictions, run the test app see if it works. You may
also want to strip out all none essential code to the bare bones.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------



"Ravi" <Ravi@discussions.microsoft.com> wrote in message
news:3C4CEF62-91D4-4783-871D-7C2C8168CC9F@microsoft.com...
> Hi Alvin,
> I have pasted my code in the first post.
> Actually, when I step into the code I can see in my Autos widow the Cache
> object having a count = 1 and when it executes The next Cache.Add the
> count
> becomes zero 0(Note: I tried doing this using both Cache.Insert and
> Cache.Add). Can you please direct me where and what should i look to
> track
> down the problem. I have tested this app with 1 item in cache and it works
> perfectly fine and gets invalidated when the corresponding result set
> changes. But I am not able to test it for two items because of the above
> issue.
>
> Thanks,
> Ravi
>
> "Alvin Bruney [ASP.NET MVP]" wrote:
>
>> I can't be certain that the cache eviction is because of the other
>> insert.
>> You perhaps need to explain a bit more. Typically this isn't an issue and
>> you should be able to have multiple dependencies.
>>
>> --
>>
>> Regards,
>> Alvin Bruney [MVP ASP.NET]
>>
>> [Shameless Author plug]
>> The O.W.C. Black Book, 2nd Edition
>> Exclusively on www.lulu.com/owc $19.99
>> -------------------------------------------------------
>>
>>
>>
>> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
>> news:21FE9A7A-B207-4DAB-821E-E95D1E5C6FC2@microsoft.com...
>> > Hi Alvin,
>> > Does this mean we cannot add two object in cache having same
>> > sql
>> > dependency?
>> >
>> > Thanks,
>> > Ravi
>> >
>> > "Alvin Bruney [ASP.NET MVP]" wrote:
>> >
>> >> This is by design, the cache scavenging mechanism is overly aggressive
>> >> in
>> >> .NET+
>> >>
>> >> --
>> >>
>> >> Regards,
>> >> Alvin Bruney [MVP ASP.NET]
>> >>
>> >> [Shameless Author plug]
>> >> The O.W.C. Black Book, 2nd Edition
>> >> Exclusively on www.lulu.com/owc $19.99
>> >> -------------------------------------------------------
>> >>
>> >>
>> >>
>> >> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
>> >> news:E379D674-BD6D-4D09-A0DA-8616F1FB1965@microsoft.com...
>> >> > Hi,
>> >> > Am using SqlDependecy for ASP.Net cache. The sql databse is
>> >> > enabled
>> >> > for
>> >> > notifications. I have added the SqlDependency.Start in my
>> >> > application_start.
>> >> > I have a command object which retrives values from table based in a
>> >> > filter
>> >> > condition. I have two cache object depending on this command object.
>> >> > After
>> >> > the first object (i.e T1) is added to cache when the control
>> >> > executes
>> >> > the
>> >> > cache.insert for adding T2 , T1 is removed from Cache. Is this
>> >> > expected
>> >> > behaviour?
>> >> >
>> >> > I have added sample code for reference,
>> >> >
>> >> >
>> >> > SqlCommand cmd = new SqlCommand();
>> >> > cmd.Connection = con;
>> >> > cmd.CommandText = "dbo.GetAllTasks";
>> >> > cmd.CommandType = CommandType.StoredProcedure;
>> >> > cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
>> >> > cmd.Parameters["@TNAME"].Value = "T1";
>> >> > cmd.Prepare();
>> >> > System.Web.Caching.CacheDependency sqldependency = new
>> >> > System.Web.Caching.SqlCacheDependency(cmd);
>> >> >
>> >> > SqlDataAdapter da = new SqlDataAdapter(cmd);
>> >> >
>> >> > DataSet ds = new DataSet();
>> >> > da.Fill(ds);
>> >> >
>> >> > HttpContext.Current.Cache.Add("T1", "hello",
>> >> > sqldependency,
>> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
>> >> > System.Web.Caching.Cache.NoSlidingExpiration,
>> >> > System.Web.Caching.CacheItemPriority.Normal, null);
>> >> >
>> >> > SqlCommand cmd1 = new SqlCommand();
>> >> > cmd1.Connection = con;
>> >> > cmd1.CommandText = "dbo.GetAllTasks";
>> >> > cmd1.CommandType = CommandType.StoredProcedure;
>> >> > cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
>> >> > cmd1.Parameters["@TNAME"].Value = "T2";
>> >> > cmd1.Prepare();
>> >> > System.Web.Caching.CacheDependency sqldependency1 = new
>> >> > System.Web.Caching.SqlCacheDependency(cmd1);
>> >> > SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
>> >> > DataSet ds1 = new DataSet();
>> >> > da1.Fill(ds1);
>> >> > HttpContext.Current.Cache.Add("T3", "test",
>> >> > sqldependency1,
>> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
>> >> > System.Web.Caching.Cache.NoSlidingExpiration,
>> >> > System.Web.Caching.CacheItemPriority.Normal, null);
>> >> >
>> >>
>>

Ravi

1/29/2008 7:19:00 AM

0

Hi Alvin,
Changing the priority worked and I was able to add items to cache.
However I have another problem, if the underlying resultset for cache item 1
is changed both cache item 1 and item 2 gets removed from cache. I expected
only item 1 to be removed and not item 2 it looks like all items from cache
will be removed if it has the same command object as dependency even if the
result sets are different?
Please let me know if you need more elaboration on my question.

Thanks,
Ravi


"Alvin Bruney [ASP.NET MVP]" wrote:

> Try this, set the cache experiation to nonremove a la
> System.Web.Caching.CacheItemPriority.Normal
> That should prevent evictions, run the test app see if it works. You may
> also want to strip out all none essential code to the bare bones.
>
> --
>
> Regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> The O.W.C. Black Book, 2nd Edition
> Exclusively on www.lulu.com/owc $19.99
> -------------------------------------------------------
>
>
>
> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
> news:3C4CEF62-91D4-4783-871D-7C2C8168CC9F@microsoft.com...
> > Hi Alvin,
> > I have pasted my code in the first post.
> > Actually, when I step into the code I can see in my Autos widow the Cache
> > object having a count = 1 and when it executes The next Cache.Add the
> > count
> > becomes zero 0(Note: I tried doing this using both Cache.Insert and
> > Cache.Add). Can you please direct me where and what should i look to
> > track
> > down the problem. I have tested this app with 1 item in cache and it works
> > perfectly fine and gets invalidated when the corresponding result set
> > changes. But I am not able to test it for two items because of the above
> > issue.
> >
> > Thanks,
> > Ravi
> >
> > "Alvin Bruney [ASP.NET MVP]" wrote:
> >
> >> I can't be certain that the cache eviction is because of the other
> >> insert.
> >> You perhaps need to explain a bit more. Typically this isn't an issue and
> >> you should be able to have multiple dependencies.
> >>
> >> --
> >>
> >> Regards,
> >> Alvin Bruney [MVP ASP.NET]
> >>
> >> [Shameless Author plug]
> >> The O.W.C. Black Book, 2nd Edition
> >> Exclusively on www.lulu.com/owc $19.99
> >> -------------------------------------------------------
> >>
> >>
> >>
> >> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
> >> news:21FE9A7A-B207-4DAB-821E-E95D1E5C6FC2@microsoft.com...
> >> > Hi Alvin,
> >> > Does this mean we cannot add two object in cache having same
> >> > sql
> >> > dependency?
> >> >
> >> > Thanks,
> >> > Ravi
> >> >
> >> > "Alvin Bruney [ASP.NET MVP]" wrote:
> >> >
> >> >> This is by design, the cache scavenging mechanism is overly aggressive
> >> >> in
> >> >> .NET+
> >> >>
> >> >> --
> >> >>
> >> >> Regards,
> >> >> Alvin Bruney [MVP ASP.NET]
> >> >>
> >> >> [Shameless Author plug]
> >> >> The O.W.C. Black Book, 2nd Edition
> >> >> Exclusively on www.lulu.com/owc $19.99
> >> >> -------------------------------------------------------
> >> >>
> >> >>
> >> >>
> >> >> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
> >> >> news:E379D674-BD6D-4D09-A0DA-8616F1FB1965@microsoft.com...
> >> >> > Hi,
> >> >> > Am using SqlDependecy for ASP.Net cache. The sql databse is
> >> >> > enabled
> >> >> > for
> >> >> > notifications. I have added the SqlDependency.Start in my
> >> >> > application_start.
> >> >> > I have a command object which retrives values from table based in a
> >> >> > filter
> >> >> > condition. I have two cache object depending on this command object.
> >> >> > After
> >> >> > the first object (i.e T1) is added to cache when the control
> >> >> > executes
> >> >> > the
> >> >> > cache.insert for adding T2 , T1 is removed from Cache. Is this
> >> >> > expected
> >> >> > behaviour?
> >> >> >
> >> >> > I have added sample code for reference,
> >> >> >
> >> >> >
> >> >> > SqlCommand cmd = new SqlCommand();
> >> >> > cmd.Connection = con;
> >> >> > cmd.CommandText = "dbo.GetAllTasks";
> >> >> > cmd.CommandType = CommandType.StoredProcedure;
> >> >> > cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> >> >> > cmd.Parameters["@TNAME"].Value = "T1";
> >> >> > cmd.Prepare();
> >> >> > System.Web.Caching.CacheDependency sqldependency = new
> >> >> > System.Web.Caching.SqlCacheDependency(cmd);
> >> >> >
> >> >> > SqlDataAdapter da = new SqlDataAdapter(cmd);
> >> >> >
> >> >> > DataSet ds = new DataSet();
> >> >> > da.Fill(ds);
> >> >> >
> >> >> > HttpContext.Current.Cache.Add("T1", "hello",
> >> >> > sqldependency,
> >> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> >> >> > System.Web.Caching.Cache.NoSlidingExpiration,
> >> >> > System.Web.Caching.CacheItemPriority.Normal, null);
> >> >> >
> >> >> > SqlCommand cmd1 = new SqlCommand();
> >> >> > cmd1.Connection = con;
> >> >> > cmd1.CommandText = "dbo.GetAllTasks";
> >> >> > cmd1.CommandType = CommandType.StoredProcedure;
> >> >> > cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
> >> >> > cmd1.Parameters["@TNAME"].Value = "T2";
> >> >> > cmd1.Prepare();
> >> >> > System.Web.Caching.CacheDependency sqldependency1 = new
> >> >> > System.Web.Caching.SqlCacheDependency(cmd1);
> >> >> > SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
> >> >> > DataSet ds1 = new DataSet();
> >> >> > da1.Fill(ds1);
> >> >> > HttpContext.Current.Cache.Add("T3", "test",
> >> >> > sqldependency1,
> >> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
> >> >> > System.Web.Caching.Cache.NoSlidingExpiration,
> >> >> > System.Web.Caching.CacheItemPriority.Normal, null);
> >> >> >
> >> >>
> >>
>

Alvin Bruney [ASP.NET MVP]

1/30/2008 1:45:00 PM

0

I'm a bit puzzled, is your code removing the items from the Cache or is it
the framework? I don't see that from your code.

--

Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The O.W.C. Black Book, 2nd Edition
Exclusively on www.lulu.com/owc $19.99
-------------------------------------------------------



"Ravi" <Ravi@discussions.microsoft.com> wrote in message
news:3006E205-40C2-4307-B227-F7FE920BE9DD@microsoft.com...
> Hi Alvin,
> Changing the priority worked and I was able to add items to
> cache.
> However I have another problem, if the underlying resultset for cache item
> 1
> is changed both cache item 1 and item 2 gets removed from cache. I
> expected
> only item 1 to be removed and not item 2 it looks like all items from
> cache
> will be removed if it has the same command object as dependency even if
> the
> result sets are different?
> Please let me know if you need more elaboration on my question.
>
> Thanks,
> Ravi
>
>
> "Alvin Bruney [ASP.NET MVP]" wrote:
>
>> Try this, set the cache experiation to nonremove a la
>> System.Web.Caching.CacheItemPriority.Normal
>> That should prevent evictions, run the test app see if it works. You may
>> also want to strip out all none essential code to the bare bones.
>>
>> --
>>
>> Regards,
>> Alvin Bruney [MVP ASP.NET]
>>
>> [Shameless Author plug]
>> The O.W.C. Black Book, 2nd Edition
>> Exclusively on www.lulu.com/owc $19.99
>> -------------------------------------------------------
>>
>>
>>
>> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
>> news:3C4CEF62-91D4-4783-871D-7C2C8168CC9F@microsoft.com...
>> > Hi Alvin,
>> > I have pasted my code in the first post.
>> > Actually, when I step into the code I can see in my Autos widow the
>> > Cache
>> > object having a count = 1 and when it executes The next Cache.Add the
>> > count
>> > becomes zero 0(Note: I tried doing this using both Cache.Insert and
>> > Cache.Add). Can you please direct me where and what should i look to
>> > track
>> > down the problem. I have tested this app with 1 item in cache and it
>> > works
>> > perfectly fine and gets invalidated when the corresponding result set
>> > changes. But I am not able to test it for two items because of the
>> > above
>> > issue.
>> >
>> > Thanks,
>> > Ravi
>> >
>> > "Alvin Bruney [ASP.NET MVP]" wrote:
>> >
>> >> I can't be certain that the cache eviction is because of the other
>> >> insert.
>> >> You perhaps need to explain a bit more. Typically this isn't an issue
>> >> and
>> >> you should be able to have multiple dependencies.
>> >>
>> >> --
>> >>
>> >> Regards,
>> >> Alvin Bruney [MVP ASP.NET]
>> >>
>> >> [Shameless Author plug]
>> >> The O.W.C. Black Book, 2nd Edition
>> >> Exclusively on www.lulu.com/owc $19.99
>> >> -------------------------------------------------------
>> >>
>> >>
>> >>
>> >> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
>> >> news:21FE9A7A-B207-4DAB-821E-E95D1E5C6FC2@microsoft.com...
>> >> > Hi Alvin,
>> >> > Does this mean we cannot add two object in cache having
>> >> > same
>> >> > sql
>> >> > dependency?
>> >> >
>> >> > Thanks,
>> >> > Ravi
>> >> >
>> >> > "Alvin Bruney [ASP.NET MVP]" wrote:
>> >> >
>> >> >> This is by design, the cache scavenging mechanism is overly
>> >> >> aggressive
>> >> >> in
>> >> >> .NET+
>> >> >>
>> >> >> --
>> >> >>
>> >> >> Regards,
>> >> >> Alvin Bruney [MVP ASP.NET]
>> >> >>
>> >> >> [Shameless Author plug]
>> >> >> The O.W.C. Black Book, 2nd Edition
>> >> >> Exclusively on www.lulu.com/owc $19.99
>> >> >> -------------------------------------------------------
>> >> >>
>> >> >>
>> >> >>
>> >> >> "Ravi" <Ravi@discussions.microsoft.com> wrote in message
>> >> >> news:E379D674-BD6D-4D09-A0DA-8616F1FB1965@microsoft.com...
>> >> >> > Hi,
>> >> >> > Am using SqlDependecy for ASP.Net cache. The sql databse is
>> >> >> > enabled
>> >> >> > for
>> >> >> > notifications. I have added the SqlDependency.Start in my
>> >> >> > application_start.
>> >> >> > I have a command object which retrives values from table based in
>> >> >> > a
>> >> >> > filter
>> >> >> > condition. I have two cache object depending on this command
>> >> >> > object.
>> >> >> > After
>> >> >> > the first object (i.e T1) is added to cache when the control
>> >> >> > executes
>> >> >> > the
>> >> >> > cache.insert for adding T2 , T1 is removed from Cache. Is this
>> >> >> > expected
>> >> >> > behaviour?
>> >> >> >
>> >> >> > I have added sample code for reference,
>> >> >> >
>> >> >> >
>> >> >> > SqlCommand cmd = new SqlCommand();
>> >> >> > cmd.Connection = con;
>> >> >> > cmd.CommandText = "dbo.GetAllTasks";
>> >> >> > cmd.CommandType = CommandType.StoredProcedure;
>> >> >> > cmd.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
>> >> >> > cmd.Parameters["@TNAME"].Value = "T1";
>> >> >> > cmd.Prepare();
>> >> >> > System.Web.Caching.CacheDependency sqldependency = new
>> >> >> > System.Web.Caching.SqlCacheDependency(cmd);
>> >> >> >
>> >> >> > SqlDataAdapter da = new SqlDataAdapter(cmd);
>> >> >> >
>> >> >> > DataSet ds = new DataSet();
>> >> >> > da.Fill(ds);
>> >> >> >
>> >> >> > HttpContext.Current.Cache.Add("T1", "hello",
>> >> >> > sqldependency,
>> >> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
>> >> >> > System.Web.Caching.Cache.NoSlidingExpiration,
>> >> >> > System.Web.Caching.CacheItemPriority.Normal, null);
>> >> >> >
>> >> >> > SqlCommand cmd1 = new SqlCommand();
>> >> >> > cmd1.Connection = con;
>> >> >> > cmd1.CommandText = "dbo.GetAllTasks";
>> >> >> > cmd1.CommandType = CommandType.StoredProcedure;
>> >> >> > cmd1.Parameters.Add("@TNAME", SqlDbType.NChar, 10);
>> >> >> > cmd1.Parameters["@TNAME"].Value = "T2";
>> >> >> > cmd1.Prepare();
>> >> >> > System.Web.Caching.CacheDependency sqldependency1 =
>> >> >> > new
>> >> >> > System.Web.Caching.SqlCacheDependency(cmd1);
>> >> >> > SqlDataAdapter da1 = new SqlDataAdapter(cmd1);
>> >> >> > DataSet ds1 = new DataSet();
>> >> >> > da1.Fill(ds1);
>> >> >> > HttpContext.Current.Cache.Add("T3", "test",
>> >> >> > sqldependency1,
>> >> >> > System.Web.Caching.Cache.NoAbsoluteExpiration,
>> >> >> > System.Web.Caching.Cache.NoSlidingExpiration,
>> >> >> > System.Web.Caching.CacheItemPriority.Normal, null);
>> >> >> >
>> >> >>
>> >>
>>