473,387 Members | 1,540 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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,

-Stan
Nov 18 '05 #1
6 1200
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" <no****@yahoo.com> wrote in message
news:O8**************@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

Nov 18 '05 #2
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" <ks******@takempis.com> wrote in message
news:OY**************@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" <no****@yahoo.com> wrote in message
news:O8**************@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


Nov 18 '05 #3
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
Nov 18 '05 #4
> 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..
Nov 18 '05 #5
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

Nov 18 '05 #6
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.)

Nov 18 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Fernando Chilvarguer | last post by:
Hi, I'm retriving data from a database and storing it on the Cache Object using the following code: HttpContext.Current.Cache.Insert( cacheItemKey, contentDS, //THE DATASET WITH MY DATA...
1
by: loosecannon_1 | last post by:
Hello everyone, I am hoping someone can help me with this problem. I will say up front that I am not a SQL Server DBA, I am a developer. I have an application that sends about 25 simultaneous...
2
by: Antonio | last post by:
Good morning, everyone. Here is the strange behavior: I have a datagrid (dgPIs) with paging enabled. When I click to view any page in the grid, it runs the private void lnkIPReg method,...
0
by: roni schuetz | last post by:
since a few day's i'm running around the problem that I stocked with a change i need to do. hopefully somebody here can give me a tipp which will be usefull to solve my problem. I'm using a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.