M
mick0987b
Hi,
Please can someone explain what is happeing here. I'm caching a list
of integers but they appear to dissapear when the original values are
changed even though there is no dependencies set up. Example code
below. Why does the cache dissapear?
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim my_int As Integer
Dim mylist As New List(Of Integer)
Dim myotherlist As New List(Of Integer)
Dim myfinallist As New List(Of Integer)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Write("Adding value to my_int - [my_int=42]<br />")
my_int = 42
Response.Write("caching value of my_int
[cache('my_cached_int')=my_int<br />")
Cache("my_cached_int") = my_int
Response.Write("Clearing value of my_int - [my_int=0]<br />")
my_int = 0
Response.Write("Getting value back from cache (I expect it
still to be 42)<br />")
Response.Write("My_cached_int = " &
Cache("my_cached_int").ToString & "<br />")
Response.Write("<br /><br />OK that works fine<br />")
Response.Write("This time use a 'list of' integers<br />")
Response.Write("mylist is a list(of integers)<br />")
Response.Write("Adding some values, 34,65,32<br />")
mylist.Add(34)
mylist.Add(65)
mylist.Add(32)
Response.Write("caching the list to 'my_cached_list'<br />")
Cache("my_cached_list") = mylist
Response.Write("retrieve the list and check count<br />")
myotherlist = Cache("my_cached_list")
Response.Write("got " & myotherlist.Count.ToString & " items
(as expected)<br />")
Response.Write("NOW..clear the original list, not the cache,
just the list [mylist.clear()] <br />")
mylist.Clear()
Response.Write("check the count of the cached list again <br /
Response.Write("got " & myfinallist.Count.ToString & " items
(WHY HAS THE CACHE CHANGED??)<br />")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>
Please can someone explain what is happeing here. I'm caching a list
of integers but they appear to dissapear when the original values are
changed even though there is no dependencies set up. Example code
below. Why does the cache dissapear?
<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Dim my_int As Integer
Dim mylist As New List(Of Integer)
Dim myotherlist As New List(Of Integer)
Dim myfinallist As New List(Of Integer)
Protected Sub Page_Load(ByVal sender As Object, ByVal e As
System.EventArgs)
Response.Write("Adding value to my_int - [my_int=42]<br />")
my_int = 42
Response.Write("caching value of my_int
[cache('my_cached_int')=my_int<br />")
Cache("my_cached_int") = my_int
Response.Write("Clearing value of my_int - [my_int=0]<br />")
my_int = 0
Response.Write("Getting value back from cache (I expect it
still to be 42)<br />")
Response.Write("My_cached_int = " &
Cache("my_cached_int").ToString & "<br />")
Response.Write("<br /><br />OK that works fine<br />")
Response.Write("This time use a 'list of' integers<br />")
Response.Write("mylist is a list(of integers)<br />")
Response.Write("Adding some values, 34,65,32<br />")
mylist.Add(34)
mylist.Add(65)
mylist.Add(32)
Response.Write("caching the list to 'my_cached_list'<br />")
Cache("my_cached_list") = mylist
Response.Write("retrieve the list and check count<br />")
myotherlist = Cache("my_cached_list")
Response.Write("got " & myotherlist.Count.ToString & " items
(as expected)<br />")
Response.Write("NOW..clear the original list, not the cache,
just the list [mylist.clear()] <br />")
mylist.Clear()
Response.Write("check the count of the cached list again <br /
myfinallist = Cache("my_cached_list")
Response.Write("got " & myfinallist.Count.ToString & " items
(WHY HAS THE CACHE CHANGED??)<br />")
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
</form>
</body>
</html>