473,597 Members | 2,413 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.To String("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\wwwr oot\ASPX & is named
CacheOutput.asp x):

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 2154
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******@hotma il.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.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.To String("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\wwwr oot\ASPX & is named
CacheOutput.asp x):

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.IsPostBac k) 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.DataSou rce = dSet
dgMarks.DataBin d()
End Sub

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

<form runat="server">
<asp:Label ID="lblMessage " runat="server"/><br>
<asp:Button ID="btnExpireCa che" OnClick="Expire Cache" 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******@hotma il.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.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.To String("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\wwwr oot\ASPX & is named
CacheOutput.asp x):

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 "Applicatio n
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******@hotma il.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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.IsPostBac k) 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.DataSou rce = dSet
dgMarks.DataBin d()
End Sub

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

<form runat="server">
<asp:Label ID="lblMessage " runat="server"/><br>
<asp:Button ID="btnExpireCa che" OnClick="Expire Cache" 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******@hotma il.comwrote in message
news:11******* *************** @b28g2000cwb.go oglegroups.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.To String("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\wwwr oot\ASPX & is named
CacheOutput.asp x):

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 "Applicatio n
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******@hotma il.comwrote in message
news:11******** **************@ e3g2000cwe.goog legroups.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.IsPostBac k) 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.DataSou rce = dSet
dgMarks.DataBin d()
End Sub

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

<form runat="server">
<asp:Label ID="lblMessage " runat="server"/><br>
<asp:Button ID="btnExpireCa che" OnClick="Expire Cache" 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******@hotma il.comwrote in message
news:11******** **************@ b28g2000cwb.goo glegroups.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.To String("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\wwwr oot\ASPX & is named
CacheOutput.asp x):

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******@hotma il.comwrote in message
news:11******** **************@ m73g2000cwd.goo glegroups.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 "Applicatio n
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******@hotma il.comwrote in message
news:11******* *************** @e3g2000cwe.goo glegroups.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.IsPostBac k) 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.DataSou rce = dSet
dgMarks.DataBin d()
End Sub

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

<form runat="server">
<asp:Label ID="lblMessage " runat="server"/><br>
<asp:Button ID="btnExpireCa che" OnClick="Expire Cache" 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******@hotma il.comwrote in message
news:11******* *************** @b28g2000cwb.go oglegroups.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.To String("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\wwwr oot\ASPX & is named
CacheOutput.asp x):

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
2734
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 directive to vary its cache based on that property value? I.e., I have: <my:control runat="server" id="mcOne" Flag="One" /> <my:control runat="server" id="mcTwo" Flag="Two" />
0
295
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 cached, as if the outputcache is ignored. There is available RAM on the server. Other pages are cached as expected. On the development environment and on a test server, it works fine. Are there any limitations to the .NET caching, apart from RAM...
1
2153
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. This user control is used on many pages. In order to create this control, I need to access information in the Active Directory to create both the menu and other info displayed on the control. This access takes some time and I wanted to cache this...
1
6421
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! Page has expired" error message, when pushing the Back Button in my Web browser.
0
1172
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 permission but with the outputcache the request doesn't pass throught the module after the page is cached... Thanks, Fabio
1
1264
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 correctly shows this as a green comment...but don't be fooled. .NET still processes and caches the output. In my case, the ClientID values started being duplicated for a DataList object.
2
2672
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 problem went away. I put in the outputcache back and the problem is back. I am using forms authentication... and asp.net 2.0. Have you seen this problem before... any help is deeply appreciated.
1
4869
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" VaryByCustom="browser" %> After I added browser... it stopped caching pages.... is there an explanation or... did I observe the problem wrong?
3
3584
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. The search results also allows refining the search and a search button that performs a postback triggers the search. Many of the web pages in the web site have an OutputCache directive and the search results page does not. When I run the first...
0
7959
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8254
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5842
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5421
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2393
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1492
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
1226
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.