Showing posts with label cache. Show all posts
Showing posts with label cache. Show all posts

Wednesday, March 28, 2012

Strange cache behavior

Not sure if this is by design or not, but it looks weird.

I get a datatable from cache:

dt = (DataTable) Cache[CacheKey];

Then, depending on selection in dropdown list I filter it:

DataView dv = dt.DefaultView;
if (cboStatus.SelectedIndex != 0)
{
int Status = int.Parse (cboStatus.SelectedItem.Value);
dv.RowFilter = string.Format ("CollectionStatusKey = {0}", Status);
}

And then, bind it to the datagrid:

grdMain.DataSource = dv;
grdMain.DataBind();

However, if dataview filter is set first time, it stays this way. What I
mean is the change in dataview gets stored in cache and dt = (DataTable)
Cache[CacheKey] brings back the old value on the next postback.

The question is this: if I add an item to cache and then modify this item,
would the modified item be automatically changed in cache? In other words,
is cache set by value or by reference?

Thanks,

-StanWith reference types, by reference. A DataTable is a reference type.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living

"Stan" <nospam@.yahoo.com> wrote in message
news:O8yxgvZmEHA.3900@.TK2MSFTNGP10.phx.gbl...
> Not sure if this is by design or not, but it looks weird.
> I get a datatable from cache:
> dt = (DataTable) Cache[CacheKey];
> Then, depending on selection in dropdown list I filter it:
> DataView dv = dt.DefaultView;
> if (cboStatus.SelectedIndex != 0)
> {
> int Status = int.Parse (cboStatus.SelectedItem.Value);
> dv.RowFilter = string.Format ("CollectionStatusKey = {0}", Status);
> }
> And then, bind it to the datagrid:
> grdMain.DataSource = dv;
> grdMain.DataBind();
> However, if dataview filter is set first time, it stays this way. What I
> mean is the change in dataview gets stored in cache and dt = (DataTable)
> Cache[CacheKey] brings back the old value on the next postback.
> The question is this: if I add an item to cache and then modify this item,
> would the modified item be automatically changed in cache? In other words,
> is cache set by value or by reference?
> Thanks,
> -Stan
if you dont want that behavior then always store a copy.
set a copy and get a copy

--

Regards,

Hermit Dave
(http://hdave.blogspot.com)
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:OYhkV$ZmEHA.3336@.TK2MSFTNGP10.phx.gbl...
> With reference types, by reference. A DataTable is a reference type.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
> "Stan" <nospam@.yahoo.com> wrote in message
> news:O8yxgvZmEHA.3900@.TK2MSFTNGP10.phx.gbl...
>> Not sure if this is by design or not, but it looks weird.
>>
>> I get a datatable from cache:
>>
>> dt = (DataTable) Cache[CacheKey];
>>
>> Then, depending on selection in dropdown list I filter it:
>>
>> DataView dv = dt.DefaultView;
>> if (cboStatus.SelectedIndex != 0)
>> {
>> int Status = int.Parse (cboStatus.SelectedItem.Value);
>> dv.RowFilter = string.Format ("CollectionStatusKey = {0}", Status);
>> }
>>
>> And then, bind it to the datagrid:
>>
>> grdMain.DataSource = dv;
>> grdMain.DataBind();
>>
>> However, if dataview filter is set first time, it stays this way. What I
>> mean is the change in dataview gets stored in cache and dt = (DataTable)
>> Cache[CacheKey] brings back the old value on the next postback.
>>
>> The question is this: if I add an item to cache and then modify this
>> item,
>> would the modified item be automatically changed in cache? In other
>> words,
>> is cache set by value or by reference?
>>
>> Thanks,
>>
>> -Stan
>>
>>
Stan wrote:

>Not sure if this is by design or not, but it looks weird.
>I get a datatable from cache:
>dt = (DataTable) Cache[CacheKey];
>Then, depending on selection in dropdown list I filter it:
>DataView dv = dt.DefaultView;
>if (cboStatus.SelectedIndex != 0)
>{
> int Status = int.Parse (cboStatus.SelectedItem.Value);
> dv.RowFilter = string.Format ("CollectionStatusKey = {0}", Status);
>}
>And then, bind it to the datagrid:
>grdMain.DataSource = dv;
>grdMain.DataBind();
>However, if dataview filter is set first time, it stays this way. What I
>mean is the change in dataview gets stored in cache and dt = (DataTable)
>Cache[CacheKey] brings back the old value on the next postback.
>The question is this: if I add an item to cache and then modify this item,
>would the modified item be automatically changed in cache? In other words,
>is cache set by value or by reference?
>Thanks,
>-Stan
>
>
You need to update cache with the latest version. It doesn't
automatically update cache.

--

SevDer
http://www.sevder.com
> You need to update cache with the latest version. It doesn't
> automatically update cache.

That is what I thought, but it does update itslef by reference..
Yes Stan,

The Cache collection maintain the reference type objects by reference is by
design behavior and regarding on this, we can just think it as other
serverside data stores such as SessionState , ApplicationState...

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Stan,

Have you had any further ideas on this issue? If there is anything else we
can help, please feel free to post here. Thanks.

Regards,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Strange cache behavior

Not sure if this is by design or not, but it looks weird.
I get a datatable from cache:
dt = (DataTable) Cache[CacheKey];
Then, depending on selection in dropdown list I filter it:
DataView dv = dt.DefaultView;
if (cboStatus.SelectedIndex != 0)
{
int Status = int.Parse (cboStatus.SelectedItem.Value);
dv.RowFilter = string.Format ("CollectionStatusKey = {0}", Status);
}
And then, bind it to the datagrid:
grdMain.DataSource = dv;
grdMain.DataBind();
However, if dataview filter is set first time, it stays this way. What I
mean is the change in dataview gets stored in cache and dt = (DataTable)
Cache[CacheKey] brings back the old value on the next postback.
The question is this: if I add an item to cache and then modify this item,
would the modified item be automatically changed in cache? In other words,
is cache set by value or by reference?
Thanks,
-StanWith reference types, by reference. A DataTable is a reference type.
HTH,
Kevin Spencer
.Net Developer
Microsoft MVP
I get paid good money to
solve puzzles for a living
"Stan" <nospam@.yahoo.com> wrote in message
news:O8yxgvZmEHA.3900@.TK2MSFTNGP10.phx.gbl...
> Not sure if this is by design or not, but it looks weird.
> I get a datatable from cache:
> dt = (DataTable) Cache[CacheKey];
> Then, depending on selection in dropdown list I filter it:
> DataView dv = dt.DefaultView;
> if (cboStatus.SelectedIndex != 0)
> {
> int Status = int.Parse (cboStatus.SelectedItem.Value);
> dv.RowFilter = string.Format ("CollectionStatusKey = {0}", Status);
> }
> And then, bind it to the datagrid:
> grdMain.DataSource = dv;
> grdMain.DataBind();
> However, if dataview filter is set first time, it stays this way. What I
> mean is the change in dataview gets stored in cache and dt = (DataTable)
> Cache[CacheKey] brings back the old value on the next postback.
> The question is this: if I add an item to cache and then modify this item,
> would the modified item be automatically changed in cache? In other words,
> is cache set by value or by reference?
> Thanks,
> -Stan
>
if you dont want that behavior then always store a copy.
set a copy and get a copy
Regards,
Hermit Dave
(http://hdave.blogspot.com)
"Kevin Spencer" <kspencer@.takempis.com> wrote in message
news:OYhkV$ZmEHA.3336@.TK2MSFTNGP10.phx.gbl...
> With reference types, by reference. A DataTable is a reference type.
> --
> HTH,
> Kevin Spencer
> .Net Developer
> Microsoft MVP
> I get paid good money to
> solve puzzles for a living
> "Stan" <nospam@.yahoo.com> wrote in message
> news:O8yxgvZmEHA.3900@.TK2MSFTNGP10.phx.gbl...
>
Stan wrote:

>Not sure if this is by design or not, but it looks weird.
>I get a datatable from cache:
>dt = (DataTable) Cache[CacheKey];
>Then, depending on selection in dropdown list I filter it:
>DataView dv = dt.DefaultView;
>if (cboStatus.SelectedIndex != 0)
>{
> int Status = int.Parse (cboStatus.SelectedItem.Value);
> dv.RowFilter = string.Format ("CollectionStatusKey = {0}", Status);
>}
>And then, bind it to the datagrid:
>grdMain.DataSource = dv;
>grdMain.DataBind();
>However, if dataview filter is set first time, it stays this way. What I
>mean is the change in dataview gets stored in cache and dt = (DataTable)
>Cache[CacheKey] brings back the old value on the next postback.
>The question is this: if I add an item to cache and then modify this item,
>would the modified item be automatically changed in cache? In other words,
>is cache set by value or by reference?
>Thanks,
>-Stan
>
>
You need to update cache with the latest version. It doesn't
automatically update cache.
SevDer
http://www.sevder.com
> You need to update cache with the latest version. It doesn't
> automatically update cache.
That is what I thought, but it does update itslef by reference..
Yes Stan,
The Cache collection maintain the reference type objects by reference is by
design behavior and regarding on this, we can just think it as other
serverside data stores such as SessionState , ApplicationState...
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
Get Preview at ASP.NET whidbey
http://msdn.microsoft.com/asp.net/whidbey/default.aspx
Hi Stan,
Have you had any further ideas on this issue? If there is anything else we
can help, please feel free to post here. Thanks.
Regards,
Steven Cheng
Microsoft Online Support
Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

Strange caching behaviour with ASP.net 2.0

Last month we upgraded our production server from .net 1.1 to 2.0. We have
seen some odd behaviour that we do not know how to fix.

It seems that Cache is reset or cleared. We have 2 or 3 global entries in
the the cache with the NotRemovable flag set. I have set up a callback that
writes an entry to the event log to see if the Cache is cleared. It appears
that it is. This happens (randomly) several times a day. I changed our global
entries to use Application state however this just seemed to amplify the
problem.

Could this be a bug with 2.0 or does a server setting need changing
somewhere (it is a windows 2003 server)?

I do not know if the cache is being reset, causing the application to crash,
or something is causing the application to crash, resulting in the cache
being reset (I have added the LegacyUnhandledExceptionPolicy enabled="true"
attribute to the web.config with no joy)

At the same time that an entry is written to say the cache has been cleared,
the performance monitor registers requests /second at 286,000,000

If anyone has experienced similar issues, can shed some light or point me in
the right direction it would be greatly appreciated.

Kind Regards,

Darrencheck the event log for asp.net recycle events. maybe you app is using too
much memeory. you should never count on a cache persistance, the fetch logic
should always handle cache empty case.

-- bruce (sqlwork.com)

"Darren Newton" <Darren Newton@.discussions.microsoft.com> wrote in message
news:2DD4A241-C2B7-44EE-9CF2-06B9BDC65B21@.microsoft.com...
> Last month we upgraded our production server from .net 1.1 to 2.0. We have
> seen some odd behaviour that we do not know how to fix.
> It seems that Cache is reset or cleared. We have 2 or 3 global entries in
> the the cache with the NotRemovable flag set. I have set up a callback
> that
> writes an entry to the event log to see if the Cache is cleared. It
> appears
> that it is. This happens (randomly) several times a day. I changed our
> global
> entries to use Application state however this just seemed to amplify the
> problem.
> Could this be a bug with 2.0 or does a server setting need changing
> somewhere (it is a windows 2003 server)?
> I do not know if the cache is being reset, causing the application to
> crash,
> or something is causing the application to crash, resulting in the cache
> being reset (I have added the LegacyUnhandledExceptionPolicy
> enabled="true"
> attribute to the web.config with no joy)
> At the same time that an entry is written to say the cache has been
> cleared,
> the performance monitor registers requests /second at 286,000,000
> If anyone has experienced similar issues, can shed some light or point me
> in
> the right direction it would be greatly appreciated.
> Kind Regards,
> Darren
Thanks for your reply.

The logic always checks if the cache item exists and repopulates if
necessary. The code worked fine in 1.1 and didn't change when we moved to
2.0. The cache doesn't appear to be repopulating - if an exception occurs the
details are e-mailed to us. The details we receive would suggest that the
cache is empty.

I have been looking through the event log but there is nothing to suggest
asp.net is being recycled.

"bruce barker (sqlwork.com)" wrote:

> check the event log for asp.net recycle events. maybe you app is using too
> much memeory. you should never count on a cache persistance, the fetch logic
> should always handle cache empty case.
> -- bruce (sqlwork.com)
> "Darren Newton" <Darren Newton@.discussions.microsoft.com> wrote in message
> news:2DD4A241-C2B7-44EE-9CF2-06B9BDC65B21@.microsoft.com...
> > Last month we upgraded our production server from .net 1.1 to 2.0. We have
> > seen some odd behaviour that we do not know how to fix.
> > It seems that Cache is reset or cleared. We have 2 or 3 global entries in
> > the the cache with the NotRemovable flag set. I have set up a callback
> > that
> > writes an entry to the event log to see if the Cache is cleared. It
> > appears
> > that it is. This happens (randomly) several times a day. I changed our
> > global
> > entries to use Application state however this just seemed to amplify the
> > problem.
> > Could this be a bug with 2.0 or does a server setting need changing
> > somewhere (it is a windows 2003 server)?
> > I do not know if the cache is being reset, causing the application to
> > crash,
> > or something is causing the application to crash, resulting in the cache
> > being reset (I have added the LegacyUnhandledExceptionPolicy
> > enabled="true"
> > attribute to the web.config with no joy)
> > At the same time that an entry is written to say the cache has been
> > cleared,
> > the performance monitor registers requests /second at 286,000,000
> > If anyone has experienced similar issues, can shed some light or point me
> > in
> > the right direction it would be greatly appreciated.
> > Kind Regards,
> > Darren
>

Strange caching behaviour with ASP.net 2.0

Last month we upgraded our production server from .net 1.1 to 2.0. We have
seen some odd behaviour that we do not know how to fix.
It seems that Cache is reset or cleared. We have 2 or 3 global entries in
the the cache with the NotRemovable flag set. I have set up a callback that
writes an entry to the event log to see if the Cache is cleared. It appears
that it is. This happens (randomly) several times a day. I changed our globa
l
entries to use Application state however this just seemed to amplify the
problem.
Could this be a bug with 2.0 or does a server setting need changing
somewhere (it is a windows 2003 server)?
I do not know if the cache is being reset, causing the application to crash,
or something is causing the application to crash, resulting in the cache
being reset (I have added the LegacyUnhandledExceptionPolicy enabled="true"
attribute to the web.config with no joy)
At the same time that an entry is written to say the cache has been cleared,
the performance monitor registers requests /second at 286,000,000
If anyone has experienced similar issues, can shed some light or point me in
the right direction it would be greatly appreciated.
Kind Regards,
Darrencheck the event log for asp.net recycle events. maybe you app is using too
much memeory. you should never count on a cache persistance, the fetch logic
should always handle cache empty case.
-- bruce (sqlwork.com)
"Darren Newton" <Darren Newton@.discussions.microsoft.com> wrote in message
news:2DD4A241-C2B7-44EE-9CF2-06B9BDC65B21@.microsoft.com...
> Last month we upgraded our production server from .net 1.1 to 2.0. We have
> seen some odd behaviour that we do not know how to fix.
> It seems that Cache is reset or cleared. We have 2 or 3 global entries in
> the the cache with the NotRemovable flag set. I have set up a callback
> that
> writes an entry to the event log to see if the Cache is cleared. It
> appears
> that it is. This happens (randomly) several times a day. I changed our
> global
> entries to use Application state however this just seemed to amplify the
> problem.
> Could this be a bug with 2.0 or does a server setting need changing
> somewhere (it is a windows 2003 server)?
> I do not know if the cache is being reset, causing the application to
> crash,
> or something is causing the application to crash, resulting in the cache
> being reset (I have added the LegacyUnhandledExceptionPolicy
> enabled="true"
> attribute to the web.config with no joy)
> At the same time that an entry is written to say the cache has been
> cleared,
> the performance monitor registers requests /second at 286,000,000
> If anyone has experienced similar issues, can shed some light or point me
> in
> the right direction it would be greatly appreciated.
> Kind Regards,
> Darren
>
Thanks for your reply.
The logic always checks if the cache item exists and repopulates if
necessary. The code worked fine in 1.1 and didn't change when we moved to
2.0. The cache doesn't appear to be repopulating - if an exception occurs th
e
details are e-mailed to us. The details we receive would suggest that the
cache is empty.
I have been looking through the event log but there is nothing to suggest
asp.net is being recycled.
"bruce barker (sqlwork.com)" wrote:

> check the event log for asp.net recycle events. maybe you app is using too
> much memeory. you should never count on a cache persistance, the fetch log
ic
> should always handle cache empty case.
> -- bruce (sqlwork.com)
> "Darren Newton" <Darren Newton@.discussions.microsoft.com> wrote in message
> news:2DD4A241-C2B7-44EE-9CF2-06B9BDC65B21@.microsoft.com...
>
>