473,320 Members | 2,112 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,320 software developers and data experts.

OutputCache?

I am using the following code to cache the page output for 60 seconds:

<%@ OutputCache Duration="60" VaryByParam="*" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
lblOutput.Text = "Welcome, " & Request.Params("id") & " The
time now is " & DateTime.Now.ToString("T")
End Sub
</script>
<form runat="server">
<asp:Label ID="lblOutput" runat="server"/>
</form>

Suppose I type the following URL in the address bar (assume that the
above ASPX page exists in C:\Inetpub\wwwroot\ASPX & is named
CacheOutput.aspx):

http://myserver/ASPX/CacheOutput.aspx?id=clive

Assume that the time shown is 2:43:18 PM. Ideally when I refresh the
page within a minute, the time should remain the same i.e. 2:43:18 PM.
Next I change the querystring value within a minute:

http://myserver/ASPX/CacheOutput.aspx?id=andrew

Now assume that the time shown is 2:43:40 PM. When I refresh the page
within a minute, the time should remain the same i.e. 2:43:40 PM.

Next I change the value of the querystring "id" back to "clive" within
a minute. The time shown should still be 2:43:18 PM (& not the current
time) since the page has been cached for a minute. Changing the "id" to
"andrew" again within a minute should show the time as 2:43:40 PM (&
not the current time).

But what I find is on some occasions, the page output gets cached
correctly for 60 seconds but on other occasions, the page either
doesn't get cached at all or it gets cached for a few seconds i.e. the
time shown continuously changes to the current time even when I refresh
the page within a minute.

What's causing this eccentricity?

Thanks,

Arpan

Aug 30 '06 #1
5 2139
Arpan:
Two thoughts.

1st - I don't think the outputcache is guaranteed to cache for X seconds.
It's more of a suggestion for ASP.NET. It'll manage it's own memory however
it thinks best.

That said, I don't think that's your problem since you are only testing it
out.

2 - The cache will dump on an application reset. If you rebuild the app,
modify the web.config, change some dlls or any other number of things, the
cache will reset. You can add perf counters to see app restarts vs cache
misses.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
>I am using the following code to cache the page output for 60 seconds:

<%@ OutputCache Duration="60" VaryByParam="*" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
lblOutput.Text = "Welcome, " & Request.Params("id") & " The
time now is " & DateTime.Now.ToString("T")
End Sub
</script>
<form runat="server">
<asp:Label ID="lblOutput" runat="server"/>
</form>

Suppose I type the following URL in the address bar (assume that the
above ASPX page exists in C:\Inetpub\wwwroot\ASPX & is named
CacheOutput.aspx):

http://myserver/ASPX/CacheOutput.aspx?id=clive

Assume that the time shown is 2:43:18 PM. Ideally when I refresh the
page within a minute, the time should remain the same i.e. 2:43:18 PM.
Next I change the querystring value within a minute:

http://myserver/ASPX/CacheOutput.aspx?id=andrew

Now assume that the time shown is 2:43:40 PM. When I refresh the page
within a minute, the time should remain the same i.e. 2:43:40 PM.

Next I change the value of the querystring "id" back to "clive" within
a minute. The time shown should still be 2:43:18 PM (& not the current
time) since the page has been cached for a minute. Changing the "id" to
"andrew" again within a minute should show the time as 2:43:40 PM (&
not the current time).

But what I find is on some occasions, the page output gets cached
correctly for 60 seconds but on other occasions, the page either
doesn't get cached at all or it gets cached for a few seconds i.e. the
time shown continuously changes to the current time even when I refresh
the page within a minute.

What's causing this eccentricity?

Thanks,

Arpan

Aug 30 '06 #2
Karl, first of all, what are these perf counters & how & where do I add
them?

Secondly, since you have said that the OutputCache is not guaranteed to
cache for X seconds, that could be one of the reasons why the code I
have shown in post #1 behaves eccentrically but here's a sample code
wherein I am using the Cache object instead of OutputCache but still
encountering similar eccentric behavior.

Here I am adding a DataSet to the cache using the Cache object. The
DataSet holds records from a SQL Server DB table which are displayed in
a DataGrid. When this ASPX page is visited for the first time, the
DataSet gets created by explicitly retrieving the records from the DB
table but on subsequent visits (or refreshes), the DataSet with the
records is retrieved from the cache. This page also has a Button
clicking which will remove the DataSet from the cache i.e. the cache
will expire & a Label which displays from where the records are being
retrieved i.e. if the DataSet has been created using the DB table
explicitly, then the Label will display a message saying "DataSet
created from DB table" else it will display "DataSet retrieved from
cache". This is the code:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal eas As EventArgs)
If Not (Page.IsPostBack) Then
Call CreateData()
End If
End Sub

Sub CreateData()
Dim dSet As DataSet

'retrieve the DataSet from the Cache object
dSet = Cache("DataSet")
If (dSet Is Nothing) Then
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter

sqlConn = New SqlConnection(".......")
sqlDapter = New SqlDataAdapter("SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill(dSet, "Marks")

'store the DataSet in the Cache object
Cache("DataSet") = dSet

lblMessage.Text = "DataSet created from DB table"
Else
lblMessage.Text = "DataSet retrieved from cache"
End If

dgMarks.DataSource = dSet
dgMarks.DataBind()
End Sub

Sub ExpireCache(ByVal obj As Object, ByVal eas As EventArgs)
'remove the DataSet from the Cache object
Cache.Remove("DataSet")
Call CreateData()
End Sub
</script>

<form runat="server">
<asp:Label ID="lblMessage" runat="server"/><br>
<asp:Button ID="btnExpireCache" OnClick="ExpireCache" Text="EXPIRE
CACHE" runat="server"/><br>
<asp:DataGrid ID="dgMarks" runat="server"/>
</form>

Here too I find that the message (whether the DataSet has been created
from the DB table or the DataSet has been retrieved from the cache) the
Label displays are erratic. For e.g. when I visit the page for the
first time, the Label says "DataSet created from DB table"....that's
fine. Next when I refresh this page, on some occasions, the Label
wrongly displays the same message & on some other occasions, the Label
correctly displays the message "DataSet retrieved from cache".

This eccentricity also comes up when I click the "EXPIRE CACHE" Button.
When the Button is clicked, the cache expires & hence the Label should
display "DataSet created from DB table" but here too, sometimes the
Label displays this message correctly & sometimes, the Label wrongly
displays "DataSet retrieved from the cache".

Note that I am not using OutputCache anywhere in the code; so why this
eccentricity? Is it something like there is no guarantee what will be
stored in the Cache object in ASP.NET?

Thanks,

Regards,

Arpan

Karl Seguin [MVP] wrote:
Arpan:
Two thoughts.

1st - I don't think the outputcache is guaranteed to cache for X seconds.
It's more of a suggestion for ASP.NET. It'll manage it's own memory however
it thinks best.

That said, I don't think that's your problem since you are only testing it
out.

2 - The cache will dump on an application reset. If you rebuild the app,
modify the web.config, change some dlls or any other number of things, the
cache will reset. You can add perf counters to see app restarts vs cache
misses.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
I am using the following code to cache the page output for 60 seconds:

<%@ OutputCache Duration="60" VaryByParam="*" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
lblOutput.Text = "Welcome, " & Request.Params("id") & " The
time now is " & DateTime.Now.ToString("T")
End Sub
</script>
<form runat="server">
<asp:Label ID="lblOutput" runat="server"/>
</form>

Suppose I type the following URL in the address bar (assume that the
above ASPX page exists in C:\Inetpub\wwwroot\ASPX & is named
CacheOutput.aspx):

http://myserver/ASPX/CacheOutput.aspx?id=clive

Assume that the time shown is 2:43:18 PM. Ideally when I refresh the
page within a minute, the time should remain the same i.e. 2:43:18 PM.
Next I change the querystring value within a minute:

http://myserver/ASPX/CacheOutput.aspx?id=andrew

Now assume that the time shown is 2:43:40 PM. When I refresh the page
within a minute, the time should remain the same i.e. 2:43:40 PM.

Next I change the value of the querystring "id" back to "clive" within
a minute. The time shown should still be 2:43:18 PM (& not the current
time) since the page has been cached for a minute. Changing the "id" to
"andrew" again within a minute should show the time as 2:43:40 PM (&
not the current time).

But what I find is on some occasions, the page output gets cached
correctly for 60 seconds but on other occasions, the page either
doesn't get cached at all or it gets cached for a few seconds i.e. the
time shown continuously changes to the current time even when I refresh
the page within a minute.

What's causing this eccentricity?

Thanks,

Arpan
Aug 31 '06 #3
Arpan:
The Cache object also isn't guaranteed not to drop. You can set a priority
(as the last argument I think)....but I even that's only a recommendation.
If this is on your own machine with little load (i.e., only you doing some
dev/test), then I wouldn't expect it to be a problem - it should cache when
you tell it to cache.

The same things that would cause your OutputCache to dump would also cause
the Cache object to dump (namely, an app reset). If you are in debug mode
(either your project or you web.config debug="true") the App Process _will_
recycle quite a bit. I'd still expect it to be pretty consistent though...so
I'm not sure this is the problem.

If you goto start --run --perfmon you can "Add counters" via the right
click, pick ASP.NET vXXXX from the Performance Object and "Application
Restart" shoudl be the first item..you should also seem caching counters.
You want to run this on the machine that your webserver is running.

Karl

P.S. - Option Strict in VB.NET is a nice option to turn on :)
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Karl, first of all, what are these perf counters & how & where do I add
them?

Secondly, since you have said that the OutputCache is not guaranteed to
cache for X seconds, that could be one of the reasons why the code I
have shown in post #1 behaves eccentrically but here's a sample code
wherein I am using the Cache object instead of OutputCache but still
encountering similar eccentric behavior.

Here I am adding a DataSet to the cache using the Cache object. The
DataSet holds records from a SQL Server DB table which are displayed in
a DataGrid. When this ASPX page is visited for the first time, the
DataSet gets created by explicitly retrieving the records from the DB
table but on subsequent visits (or refreshes), the DataSet with the
records is retrieved from the cache. This page also has a Button
clicking which will remove the DataSet from the cache i.e. the cache
will expire & a Label which displays from where the records are being
retrieved i.e. if the DataSet has been created using the DB table
explicitly, then the Label will display a message saying "DataSet
created from DB table" else it will display "DataSet retrieved from
cache". This is the code:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal eas As EventArgs)
If Not (Page.IsPostBack) Then
Call CreateData()
End If
End Sub

Sub CreateData()
Dim dSet As DataSet

'retrieve the DataSet from the Cache object
dSet = Cache("DataSet")
If (dSet Is Nothing) Then
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter

sqlConn = New SqlConnection(".......")
sqlDapter = New SqlDataAdapter("SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill(dSet, "Marks")

'store the DataSet in the Cache object
Cache("DataSet") = dSet

lblMessage.Text = "DataSet created from DB table"
Else
lblMessage.Text = "DataSet retrieved from cache"
End If

dgMarks.DataSource = dSet
dgMarks.DataBind()
End Sub

Sub ExpireCache(ByVal obj As Object, ByVal eas As EventArgs)
'remove the DataSet from the Cache object
Cache.Remove("DataSet")
Call CreateData()
End Sub
</script>

<form runat="server">
<asp:Label ID="lblMessage" runat="server"/><br>
<asp:Button ID="btnExpireCache" OnClick="ExpireCache" Text="EXPIRE
CACHE" runat="server"/><br>
<asp:DataGrid ID="dgMarks" runat="server"/>
</form>

Here too I find that the message (whether the DataSet has been created
from the DB table or the DataSet has been retrieved from the cache) the
Label displays are erratic. For e.g. when I visit the page for the
first time, the Label says "DataSet created from DB table"....that's
fine. Next when I refresh this page, on some occasions, the Label
wrongly displays the same message & on some other occasions, the Label
correctly displays the message "DataSet retrieved from cache".

This eccentricity also comes up when I click the "EXPIRE CACHE" Button.
When the Button is clicked, the cache expires & hence the Label should
display "DataSet created from DB table" but here too, sometimes the
Label displays this message correctly & sometimes, the Label wrongly
displays "DataSet retrieved from the cache".

Note that I am not using OutputCache anywhere in the code; so why this
eccentricity? Is it something like there is no guarantee what will be
stored in the Cache object in ASP.NET?

Thanks,

Regards,

Arpan

Karl Seguin [MVP] wrote:
>Arpan:
Two thoughts.

1st - I don't think the outputcache is guaranteed to cache for X seconds.
It's more of a suggestion for ASP.NET. It'll manage it's own memory
however
it thinks best.

That said, I don't think that's your problem since you are only testing
it
out.

2 - The cache will dump on an application reset. If you rebuild the app,
modify the web.config, change some dlls or any other number of things,
the
cache will reset. You can add perf counters to see app restarts vs cache
misses.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
>I am using the following code to cache the page output for 60 seconds:

<%@ OutputCache Duration="60" VaryByParam="*" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
lblOutput.Text = "Welcome, " & Request.Params("id") & " The
time now is " & DateTime.Now.ToString("T")
End Sub
</script>
<form runat="server">
<asp:Label ID="lblOutput" runat="server"/>
</form>

Suppose I type the following URL in the address bar (assume that the
above ASPX page exists in C:\Inetpub\wwwroot\ASPX & is named
CacheOutput.aspx):

http://myserver/ASPX/CacheOutput.aspx?id=clive

Assume that the time shown is 2:43:18 PM. Ideally when I refresh the
page within a minute, the time should remain the same i.e. 2:43:18 PM.
Next I change the querystring value within a minute:

http://myserver/ASPX/CacheOutput.aspx?id=andrew

Now assume that the time shown is 2:43:40 PM. When I refresh the page
within a minute, the time should remain the same i.e. 2:43:40 PM.

Next I change the value of the querystring "id" back to "clive" within
a minute. The time shown should still be 2:43:18 PM (& not the current
time) since the page has been cached for a minute. Changing the "id" to
"andrew" again within a minute should show the time as 2:43:40 PM (&
not the current time).

But what I find is on some occasions, the page output gets cached
correctly for 60 seconds but on other occasions, the page either
doesn't get cached at all or it gets cached for a few seconds i.e. the
time shown continuously changes to the current time even when I refresh
the page within a minute.

What's causing this eccentricity?

Thanks,

Arpan

Aug 31 '06 #4
If this is on your own machine with little load (i.e., only you doing some
dev/test), then I wouldn't expect it to be a problem - it should cache when
you tell it to cache.
Karl, this is my own machine with 256MB RAM. I am working on Win2K Pro.
So the load shouldn't be too much but is 256MB RAM enough for a machine
which has the .NET Framework v2.0, its entire documentation & VS.NET
2005 Express Edition (along with SQL Server 2005 Management Studio
Express & Books Online) installed? The reason I am asking this is
because when I open a project in VS.NET, it takes quite a lot of time
to open the project. Closing VS.NET takes a lot of time as well (in
fact, more than the time taken to load a project). & whenever I am
working with ASP.NET & VS.NET, once everyday, Win2K generates a message
saying that my system is running on low virtual memory (or something of
that sort).

So could the 256MB RAM be the reason why the cache is behaving
erratically?

Thanks,

Regards,

Arpan
Karl Seguin [MVP] wrote:
Arpan:
The Cache object also isn't guaranteed not to drop. You can set a priority
(as the last argument I think)....but I even that's only a recommendation.
If this is on your own machine with little load (i.e., only you doing some
dev/test), then I wouldn't expect it to be a problem - it should cache when
you tell it to cache.

The same things that would cause your OutputCache to dump would also cause
the Cache object to dump (namely, an app reset). If you are in debug mode
(either your project or you web.config debug="true") the App Process _will_
recycle quite a bit. I'd still expect it to be pretty consistent though...so
I'm not sure this is the problem.

If you goto start --run --perfmon you can "Add counters" via the right
click, pick ASP.NET vXXXX from the Performance Object and "Application
Restart" shoudl be the first item..you should also seem caching counters.
You want to run this on the machine that your webserver is running.

Karl

P.S. - Option Strict in VB.NET is a nice option to turn on :)
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegro ups.com...
Karl, first of all, what are these perf counters & how & where do I add
them?

Secondly, since you have said that the OutputCache is not guaranteed to
cache for X seconds, that could be one of the reasons why the code I
have shown in post #1 behaves eccentrically but here's a sample code
wherein I am using the Cache object instead of OutputCache but still
encountering similar eccentric behavior.

Here I am adding a DataSet to the cache using the Cache object. The
DataSet holds records from a SQL Server DB table which are displayed in
a DataGrid. When this ASPX page is visited for the first time, the
DataSet gets created by explicitly retrieving the records from the DB
table but on subsequent visits (or refreshes), the DataSet with the
records is retrieved from the cache. This page also has a Button
clicking which will remove the DataSet from the cache i.e. the cache
will expire & a Label which displays from where the records are being
retrieved i.e. if the DataSet has been created using the DB table
explicitly, then the Label will display a message saying "DataSet
created from DB table" else it will display "DataSet retrieved from
cache". This is the code:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal eas As EventArgs)
If Not (Page.IsPostBack) Then
Call CreateData()
End If
End Sub

Sub CreateData()
Dim dSet As DataSet

'retrieve the DataSet from the Cache object
dSet = Cache("DataSet")
If (dSet Is Nothing) Then
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter

sqlConn = New SqlConnection(".......")
sqlDapter = New SqlDataAdapter("SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill(dSet, "Marks")

'store the DataSet in the Cache object
Cache("DataSet") = dSet

lblMessage.Text = "DataSet created from DB table"
Else
lblMessage.Text = "DataSet retrieved from cache"
End If

dgMarks.DataSource = dSet
dgMarks.DataBind()
End Sub

Sub ExpireCache(ByVal obj As Object, ByVal eas As EventArgs)
'remove the DataSet from the Cache object
Cache.Remove("DataSet")
Call CreateData()
End Sub
</script>

<form runat="server">
<asp:Label ID="lblMessage" runat="server"/><br>
<asp:Button ID="btnExpireCache" OnClick="ExpireCache" Text="EXPIRE
CACHE" runat="server"/><br>
<asp:DataGrid ID="dgMarks" runat="server"/>
</form>

Here too I find that the message (whether the DataSet has been created
from the DB table or the DataSet has been retrieved from the cache) the
Label displays are erratic. For e.g. when I visit the page for the
first time, the Label says "DataSet created from DB table"....that's
fine. Next when I refresh this page, on some occasions, the Label
wrongly displays the same message & on some other occasions, the Label
correctly displays the message "DataSet retrieved from cache".

This eccentricity also comes up when I click the "EXPIRE CACHE" Button.
When the Button is clicked, the cache expires & hence the Label should
display "DataSet created from DB table" but here too, sometimes the
Label displays this message correctly & sometimes, the Label wrongly
displays "DataSet retrieved from the cache".

Note that I am not using OutputCache anywhere in the code; so why this
eccentricity? Is it something like there is no guarantee what will be
stored in the Cache object in ASP.NET?

Thanks,

Regards,

Arpan

Karl Seguin [MVP] wrote:
Arpan:
Two thoughts.

1st - I don't think the outputcache is guaranteed to cache for X seconds.
It's more of a suggestion for ASP.NET. It'll manage it's own memory
however
it thinks best.

That said, I don't think that's your problem since you are only testing
it
out.

2 - The cache will dump on an application reset. If you rebuild the app,
modify the web.config, change some dlls or any other number of things,
the
cache will reset. You can add perf counters to see app restarts vs cache
misses.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googlegr oups.com...
I am using the following code to cache the page output for 60 seconds:

<%@ OutputCache Duration="60" VaryByParam="*" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
lblOutput.Text = "Welcome, " & Request.Params("id") & " The
time now is " & DateTime.Now.ToString("T")
End Sub
</script>
<form runat="server">
<asp:Label ID="lblOutput" runat="server"/>
</form>

Suppose I type the following URL in the address bar (assume that the
above ASPX page exists in C:\Inetpub\wwwroot\ASPX & is named
CacheOutput.aspx):

http://myserver/ASPX/CacheOutput.aspx?id=clive

Assume that the time shown is 2:43:18 PM. Ideally when I refresh the
page within a minute, the time should remain the same i.e. 2:43:18 PM.
Next I change the querystring value within a minute:

http://myserver/ASPX/CacheOutput.aspx?id=andrew

Now assume that the time shown is 2:43:40 PM. When I refresh the page
within a minute, the time should remain the same i.e. 2:43:40 PM.

Next I change the value of the querystring "id" back to "clive" within
a minute. The time shown should still be 2:43:18 PM (& not the current
time) since the page has been cached for a minute. Changing the "id" to
"andrew" again within a minute should show the time as 2:43:40 PM (&
not the current time).

But what I find is on some occasions, the page output gets cached
correctly for 60 seconds but on other occasions, the page either
doesn't get cached at all or it gets cached for a few seconds i.e. the
time shown continuously changes to the current time even when I refresh
the page within a minute.

What's causing this eccentricity?

Thanks,

Arpan
Aug 31 '06 #5
re:
So the load shouldn't be too much but is 256MB RAM enough for a machine
which has the .NET Framework v2.0, its entire documentation & VS.NET
2005 Express Edition (along with SQL Server 2005 Management Studio
Express & Books Online) installed?
The bare minimum for that setup is 512MB RAM; 1 GB is recommended

re:
So could the 256MB RAM be the reason why the cache is behaving erratically?
Yes.

When you run out of physical RAM, the system needs to page memory to disk.
That causes all sorts of response problems.


Juan T. Llibre, asp.net MVP
aspnetfaq.com : http://www.aspnetfaq.com/
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
===================================
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>If this is on your own machine with little load (i.e., only you doing some
dev/test), then I wouldn't expect it to be a problem - it should cache when
you tell it to cache.

Karl, this is my own machine with 256MB RAM. I am working on Win2K Pro.
So the load shouldn't be too much but is 256MB RAM enough for a machine
which has the .NET Framework v2.0, its entire documentation & VS.NET
2005 Express Edition (along with SQL Server 2005 Management Studio
Express & Books Online) installed? The reason I am asking this is
because when I open a project in VS.NET, it takes quite a lot of time
to open the project. Closing VS.NET takes a lot of time as well (in
fact, more than the time taken to load a project). & whenever I am
working with ASP.NET & VS.NET, once everyday, Win2K generates a message
saying that my system is running on low virtual memory (or something of
that sort).

So could the 256MB RAM be the reason why the cache is behaving
erratically?

Thanks,

Regards,

Arpan
Karl Seguin [MVP] wrote:
>Arpan:
The Cache object also isn't guaranteed not to drop. You can set a priority
(as the last argument I think)....but I even that's only a recommendation.
If this is on your own machine with little load (i.e., only you doing some
dev/test), then I wouldn't expect it to be a problem - it should cache when
you tell it to cache.

The same things that would cause your OutputCache to dump would also cause
the Cache object to dump (namely, an app reset). If you are in debug mode
(either your project or you web.config debug="true") the App Process _will_
recycle quite a bit. I'd still expect it to be pretty consistent though...so
I'm not sure this is the problem.

If you goto start --run --perfmon you can "Add counters" via the right
click, pick ASP.NET vXXXX from the Performance Object and "Application
Restart" shoudl be the first item..you should also seem caching counters.
You want to run this on the machine that your webserver is running.

Karl

P.S. - Option Strict in VB.NET is a nice option to turn on :)
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@e3g2000cwe.googlegr oups.com...
Karl, first of all, what are these perf counters & how & where do I add
them?

Secondly, since you have said that the OutputCache is not guaranteed to
cache for X seconds, that could be one of the reasons why the code I
have shown in post #1 behaves eccentrically but here's a sample code
wherein I am using the Cache object instead of OutputCache but still
encountering similar eccentric behavior.

Here I am adding a DataSet to the cache using the Cache object. The
DataSet holds records from a SQL Server DB table which are displayed in
a DataGrid. When this ASPX page is visited for the first time, the
DataSet gets created by explicitly retrieving the records from the DB
table but on subsequent visits (or refreshes), the DataSet with the
records is retrieved from the cache. This page also has a Button
clicking which will remove the DataSet from the cache i.e. the cache
will expire & a Label which displays from where the records are being
retrieved i.e. if the DataSet has been created using the DB table
explicitly, then the Label will display a message saying "DataSet
created from DB table" else it will display "DataSet retrieved from
cache". This is the code:

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal eas As EventArgs)
If Not (Page.IsPostBack) Then
Call CreateData()
End If
End Sub

Sub CreateData()
Dim dSet As DataSet

'retrieve the DataSet from the Cache object
dSet = Cache("DataSet")
If (dSet Is Nothing) Then
Dim sqlConn As SqlConnection
Dim sqlDapter As SqlDataAdapter

sqlConn = New SqlConnection(".......")
sqlDapter = New SqlDataAdapter("SELECT * FROM tblMarks",
sqlConn)
dSet = New DataSet
sqlDapter.Fill(dSet, "Marks")

'store the DataSet in the Cache object
Cache("DataSet") = dSet

lblMessage.Text = "DataSet created from DB table"
Else
lblMessage.Text = "DataSet retrieved from cache"
End If

dgMarks.DataSource = dSet
dgMarks.DataBind()
End Sub

Sub ExpireCache(ByVal obj As Object, ByVal eas As EventArgs)
'remove the DataSet from the Cache object
Cache.Remove("DataSet")
Call CreateData()
End Sub
</script>

<form runat="server">
<asp:Label ID="lblMessage" runat="server"/><br>
<asp:Button ID="btnExpireCache" OnClick="ExpireCache" Text="EXPIRE
CACHE" runat="server"/><br>
<asp:DataGrid ID="dgMarks" runat="server"/>
</form>

Here too I find that the message (whether the DataSet has been created
from the DB table or the DataSet has been retrieved from the cache) the
Label displays are erratic. For e.g. when I visit the page for the
first time, the Label says "DataSet created from DB table"....that's
fine. Next when I refresh this page, on some occasions, the Label
wrongly displays the same message & on some other occasions, the Label
correctly displays the message "DataSet retrieved from cache".

This eccentricity also comes up when I click the "EXPIRE CACHE" Button.
When the Button is clicked, the cache expires & hence the Label should
display "DataSet created from DB table" but here too, sometimes the
Label displays this message correctly & sometimes, the Label wrongly
displays "DataSet retrieved from the cache".

Note that I am not using OutputCache anywhere in the code; so why this
eccentricity? Is it something like there is no guarantee what will be
stored in the Cache object in ASP.NET?

Thanks,

Regards,

Arpan

Karl Seguin [MVP] wrote:
Arpan:
Two thoughts.

1st - I don't think the outputcache is guaranteed to cache for X seconds.
It's more of a suggestion for ASP.NET. It'll manage it's own memory
however
it thinks best.

That said, I don't think that's your problem since you are only testing
it
out.

2 - The cache will dump on an application reset. If you rebuild the app,
modify the web.config, change some dlls or any other number of things,
the
cache will reset. You can add perf counters to see app restarts vs cache
misses.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Arpan" <ar******@hotmail.comwrote in message
news:11**********************@b28g2000cwb.googleg roups.com...
I am using the following code to cache the page output for 60 seconds:

<%@ OutputCache Duration="60" VaryByParam="*" %>

<script runat="server">
Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)
lblOutput.Text = "Welcome, " & Request.Params("id") & " The
time now is " & DateTime.Now.ToString("T")
End Sub
</script>
<form runat="server">
<asp:Label ID="lblOutput" runat="server"/>
</form>

Suppose I type the following URL in the address bar (assume that the
above ASPX page exists in C:\Inetpub\wwwroot\ASPX & is named
CacheOutput.aspx):

http://myserver/ASPX/CacheOutput.aspx?id=clive

Assume that the time shown is 2:43:18 PM. Ideally when I refresh the
page within a minute, the time should remain the same i.e. 2:43:18 PM.
Next I change the querystring value within a minute:

http://myserver/ASPX/CacheOutput.aspx?id=andrew

Now assume that the time shown is 2:43:40 PM. When I refresh the page
within a minute, the time should remain the same i.e. 2:43:40 PM.

Next I change the value of the querystring "id" back to "clive" within
a minute. The time shown should still be 2:43:18 PM (& not the current
time) since the page has been cached for a minute. Changing the "id" to
"andrew" again within a minute should show the time as 2:43:40 PM (&
not the current time).

But what I find is on some occasions, the page output gets cached
correctly for 60 seconds but on other occasions, the page either
doesn't get cached at all or it gets cached for a few seconds i.e. the
time shown continuously changes to the current time even when I refresh
the page within a minute.

What's causing this eccentricity?

Thanks,

Arpan


Sep 1 '06 #6

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

Similar topics

6
by: Tom Kiefer | last post by:
Question: If I have an ASP.NET User Control which defines/exposes a property that the page can use to specify a mode or data subset for the control to use, is there a way to tell the @OutputCache...
0
by: Vassilis T. via .NET 247 | last post by:
The following piece of code, when on a heavily loaded server (more than 50 ASP.NET pages, most using outputcache with varybyparam, lots of users), will only cache the string - the output is not...
1
by: Barbara Alderton | last post by:
I have the following scenario: I have a user control that contains a registered menu control. The menu and other information on the user control is specific to the user accessing the site. ...
1
by: Johan Nedin | last post by:
Hello! I am having a problem with the @OutputCache page directive and Web browser Back Buttons. Problem: After setting <%@ OutputCache Location="None" %> on my pages I get the "Warning!...
0
by: Fabio R. | last post by:
Hi, is there a way to have an HttpModule working also if the page has the OutputCache directive (<%@ OutputCache Duration="60" VaryByParam="none"%>)? I use an HttpModule to check some access...
1
by: Amil Hanish | last post by:
I had an aspx page with output caching turned on. Then I wanted to do some other stuff and I commented it out like: <!-- <%@ OutputCache Duration="1800" VaryByParam="t" %> --> The IDE...
2
by: Nalaka | last post by:
Hi, I get the following error, I thought at random intervals. Then I realized, that this happens around the time tha page outputCache is set to expire. So I disabled the page output cache and the...
1
by: Nalaka | last post by:
I had ..... <%@ OutputCache Duration="5000" Location="Server" VaryByParam="none" %> Then I added "browser" <%@ OutputCache Duration="5000" Location="Server" VaryByParam="none"...
3
by: =?Utf-8?B?TWlndWVsIElzaWRvcm8=?= | last post by:
Hi, I have an ASP.NET 2.0 application that allows content search. Search is included in all pages and a cross postback to the search results page is performed with the text inserted by the user....
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.