HighTechTalks DotNet Forums  

Cache problem

ASP.net Caching microsoft.public.dotnet.framework.aspnet.caching


Discuss Cache problem in the ASP.net Caching forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
zino
 
Posts: n/a

Default Cache problem - 05-04-2007 , 05:04 PM






in ASP net 2.0
a function that query/add item to cache:
public function1
.... ... ..
If HttpContext.Current.Cache(myKey) Is Nothing Then
Dim ds As DataSet = functionToCreateDataset.... ...
HttpContext.Current.Cache.Insert(myKey, ds, Nothing)
End If
Return HttpContext.Current.Cache

in the web form code behind, I have:
Dim ds As DataSet = Cache("myKey")
dim ds as dataset
ds.Tables(0).Columns.Add("customCol", GetType(String), "col1+'- '+col2")


the problem is, when "function1" create the cache the first time, the
statement:
ds.Tables(0).Columns.Add("col1", GetType(String), "col1+'- '+col2")
works fine. But when "function1" returned the cached item, the same
statement display the error:
"A column named 'customCol' already belongs to this DataTable."

it looks like the cache get changed too when the dataset derived from it is
changed.
how can I fix that ?

Reply With Quote
  #2  
Old   
Alvin Bruney [MVP]
 
Posts: n/a

Default Re: Cache problem - 05-05-2007 , 09:30 AM






This is an error, you have ds declared twice, it's most likely a typo. I
wouldn't expect that to compile:

Dim ds As DataSet = Cache("myKey")
dim ds as dataset

When you first create your dataset, it contains a column named customCol.
You can, at any point later, add another column with that name because
column names are explicitly unique.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"zino" <zino (AT) noemail (DOT) noemail> wrote

Quote:
in ASP net 2.0
a function that query/add item to cache:
public function1
... ... ..
If HttpContext.Current.Cache(myKey) Is Nothing Then
Dim ds As DataSet = functionToCreateDataset.... ...
HttpContext.Current.Cache.Insert(myKey, ds, Nothing)
End If
Return HttpContext.Current.Cache

in the web form code behind, I have:
Dim ds As DataSet = Cache("myKey")
dim ds as dataset
ds.Tables(0).Columns.Add("customCol", GetType(String), "col1+'- '+col2")


the problem is, when "function1" create the cache the first time, the
statement:
ds.Tables(0).Columns.Add("col1", GetType(String), "col1+'- '+col2")
works fine. But when "function1" returned the cached item, the same
statement display the error:
"A column named 'customCol' already belongs to this DataTable."

it looks like the cache get changed too when the dataset derived from it
is
changed.
how can I fix that ?



Reply With Quote
  #3  
Old   
zino
 
Posts: n/a

Default Re: Cache problem - 05-07-2007 , 09:47 AM



there is a little confusion here.
the issue is :
- a datatable consisting of 2 column is created and added to the cache.
(cache("myDt") )

- a variable derived from a call to this cache :
Dim dt2 As DataTable = CType(Cache("myDt"), DataTable)

the following: dt2.Columns.Count will return: 2


now,
any change to dt2 as:
dt2.Columns.Add("customCol", GetType(String), "col1+'- '+col2") , is
changing cache("myDt") too.

after the previous statement:
the following:
Dim dt3 As DataTable = CType(Cache("myDt"), DataTable)
dt3.Columns.Count will return: 3


why 3 ??
Why the change done on dt2 propagated back to the cache ?






Reply With Quote
  #4  
Old   
Alvin Bruney [MVP]
 
Posts: n/a

Default Re: Cache problem - 05-07-2007 , 07:20 PM



Sorry if I am out of left field because the original thread isn't included.
Cache holds live object references not copies. Well, the copy is a pointer
reference that *points to the live object.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"zino" <zino (AT) noemail (DOT) noemail> wrote

Quote:
there is a little confusion here.
the issue is :
- a datatable consisting of 2 column is created and added to the cache.
(cache("myDt") )

- a variable derived from a call to this cache :
Dim dt2 As DataTable = CType(Cache("myDt"), DataTable)

the following: dt2.Columns.Count will return: 2


now,
any change to dt2 as:
dt2.Columns.Add("customCol", GetType(String), "col1+'- '+col2") , is
changing cache("myDt") too.

after the previous statement:
the following:
Dim dt3 As DataTable = CType(Cache("myDt"), DataTable)
dt3.Columns.Count will return: 3


why 3 ??
Why the change done on dt2 propagated back to the cache ?








Reply With Quote
  #5  
Old   
zino
 
Posts: n/a

Default Re: Cache problem - 05-08-2007 , 08:20 AM



Thank you.
that answers my question.

"Alvin Bruney [MVP]" wrote:

Quote:
Sorry if I am out of left field because the original thread isn't included.
Cache holds live object references not copies. Well, the copy is a pointer
reference that *points to the live object.

--
Regards,
Alvin Bruney
------------------------------------------------------
Shameless author plug
Excel Services for .NET is coming...
OWC Black book on Amazon and
www.lulu.com/owc
Professional VSTO 2005 - Wrox/Wiley


"zino" <zino (AT) noemail (DOT) noemail> wrote in message
news:7FDEF93B-392A-460A-A74E-516D4DA25ABB (AT) microsoft (DOT) com...
there is a little confusion here.
the issue is :
- a datatable consisting of 2 column is created and added to the cache.
(cache("myDt") )

- a variable derived from a call to this cache :
Dim dt2 As DataTable = CType(Cache("myDt"), DataTable)

the following: dt2.Columns.Count will return: 2


now,
any change to dt2 as:
dt2.Columns.Add("customCol", GetType(String), "col1+'- '+col2") , is
changing cache("myDt") too.

after the previous statement:
the following:
Dim dt3 As DataTable = CType(Cache("myDt"), DataTable)
dt3.Columns.Count will return: 3


why 3 ??
Why the change done on dt2 propagated back to the cache ?









Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.