473,320 Members | 1,969 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.

ASPNET cache cannot refresh

I used
HttpContext.Current.Cache["Categories"] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Current.Cache["Categories"] == null ) {
HttpContext.Current.Cache["Categories"] = GetCategoriesFromDB();
}
return (DataView)HttpContext.Current.Cache["Categories"];}

However when database data changed, the page still keept the cached data no
matter how many times I refresh the page. I closed the browser, and reopened
it, and it had no effect. Finally I restarted the machine, the data then
refreshed. Is that the correct way for ASPNET cache work?

Nov 19 '05 #1
6 1956
Hi!

If you use the HttpContext.Current.Cache.Add(...) method instead, you can
specify the length of time before the cached object is reset. See the
documentation here:
http://msdn.microsoft.com/library/en...asp?frame=true

If you only set the item by using the indexer, you cache the item forever or
until the application is reset.
You could, however, write some code in the page that updates the data, that
resets the cache object again. That would keep the cache syncronized at all
times.

HTH,
Lars-Erik

"Charts" <Ac*****@newsgroup.nospam> wrote in message
news:2F**********************************@microsof t.com...
I used
HttpContext.Current.Cache["Categories"] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Current.Cache["Categories"] == null ) {
HttpContext.Current.Cache["Categories"] = GetCategoriesFromDB();
}
return (DataView)HttpContext.Current.Cache["Categories"];}

However when database data changed, the page still keept the cached data
no
matter how many times I refresh the page. I closed the browser, and
reopened
it, and it had no effect. Finally I restarted the machine, the data then
refreshed. Is that the correct way for ASPNET cache work?

Nov 19 '05 #2
The cache knows nothing about your changes to data in the DB.

You have to make some choices.
1. Expire the cache periodically and live with possibly stale data until it
is refreshed.

2. Use the new 2.0 stuff for invalidating the cache based on changes to the
DB.
(I have not seen it yet.)

3. Use code to poll the DB for changes and then invalidate the cache.
I use this technique. Works well.

See this article for how to do it: (note my comments on the bootm of the
page.)
http://www.eggheadcafe.com/articles/20040607.asp

--
Joe Fallon

"Charts" <Ac*****@newsgroup.nospam> wrote in message
news:2F**********************************@microsof t.com...
I used
HttpContext.Current.Cache["Categories"] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Current.Cache["Categories"] == null ) {
HttpContext.Current.Cache["Categories"] = GetCategoriesFromDB();
}
return (DataView)HttpContext.Current.Cache["Categories"];}

However when database data changed, the page still keept the cached data
no
matter how many times I refresh the page. I closed the browser, and
reopened
it, and it had no effect. Finally I restarted the machine, the data then
refreshed. Is that the correct way for ASPNET cache work?

Nov 19 '05 #3
Thanks for your input Erik,

Hi Charts,

As Erik has mentioned, we are recommended to use the ASP.NET's Application
Cache through the

HttpContext.Cache.Add(.....) (or Insert method) rather than simply use the

Cache["key"] = value.....

since using the Cache["key"] will cause the added object be persisted in
the memory and won't be removed until the application restart.......

And by using the Cache.Add method, we can add expire policy for the cached
object, such as TimeSpan or FileDependency.

Here are some msdn reference which may also be helpful:

http://msdn.microsoft.com/msdnmag/is...e/default.aspx

http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcacheapis.asp

Thanks,

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
--------------------
| Reply-To: "Lars-Erik Aabech" <la******@newsgroup.nospam>
| From: "Lars-Erik Aabech" <la******@newsgroup.nospam>
| References: <2F**********************************@microsoft.co m>
| Subject: Re: ASPNET cache cannot refresh
| Date: Wed, 6 Jul 2005 17:16:16 +0200
| Lines: 37
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
| X-RFC2646: Format=Flowed; Original
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
| Message-ID: <#T**************@TK2MSFTNGP09.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: host-81-191-131-56.bluecom.no 81.191.131.56
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFT NGP09.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:110651
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Hi!
|
| If you use the HttpContext.Current.Cache.Add(...) method instead, you can
| specify the length of time before the cached object is reset. See the
| documentation here:
|
http://msdn.microsoft.com/library/en...webcachingcach
eclassaddtopic.asp?frame=true
|
| If you only set the item by using the indexer, you cache the item forever
or
| until the application is reset.
| You could, however, write some code in the page that updates the data,
that
| resets the cache object again. That would keep the cache syncronized at
all
| times.
|
| HTH,
| Lars-Erik
|
| "Charts" <Ac*****@newsgroup.nospam> wrote in message
| news:2F**********************************@microsof t.com...
| >I used
| > HttpContext.Current.Cache["Categories"] To cache data from database.
| > The code is like that.
| >
| > public static DataView GetCategories() {
| > if ( HttpContext.Current.Cache["Categories"] == null ) {
| > HttpContext.Current.Cache["Categories"] = GetCategoriesFromDB();
| > }
| > return (DataView)HttpContext.Current.Cache["Categories"];}
| >
| > However when database data changed, the page still keept the cached
data
| > no
| > matter how many times I refresh the page. I closed the browser, and
| > reopened
| > it, and it had no effect. Finally I restarted the machine, the data
then
| > refreshed. Is that the correct way for ASPNET cache work?
| >
|
|
|

Nov 19 '05 #4
Thanks

"Joe Fallon" wrote:
The cache knows nothing about your changes to data in the DB.

You have to make some choices.
1. Expire the cache periodically and live with possibly stale data until it
is refreshed.

2. Use the new 2.0 stuff for invalidating the cache based on changes to the
DB.
(I have not seen it yet.)

3. Use code to poll the DB for changes and then invalidate the cache.
I use this technique. Works well.

See this article for how to do it: (note my comments on the bootm of the
page.)
http://www.eggheadcafe.com/articles/20040607.asp

--
Joe Fallon

"Charts" <Ac*****@newsgroup.nospam> wrote in message
news:2F**********************************@microsof t.com...
I used
HttpContext.Current.Cache["Categories"] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Current.Cache["Categories"] == null ) {
HttpContext.Current.Cache["Categories"] = GetCategoriesFromDB();
}
return (DataView)HttpContext.Current.Cache["Categories"];}

However when database data changed, the page still keept the cached data
no
matter how many times I refresh the page. I closed the browser, and
reopened
it, and it had no effect. Finally I restarted the machine, the data then
refreshed. Is that the correct way for ASPNET cache work?


Nov 19 '05 #5
Thanks guys, It is very helpful. Charts

"Lars-Erik Aabech" wrote:
Hi!

If you use the HttpContext.Current.Cache.Add(...) method instead, you can
specify the length of time before the cached object is reset. See the
documentation here:
http://msdn.microsoft.com/library/en...asp?frame=true

If you only set the item by using the indexer, you cache the item forever or
until the application is reset.
You could, however, write some code in the page that updates the data, that
resets the cache object again. That would keep the cache syncronized at all
times.

HTH,
Lars-Erik

"Charts" <Ac*****@newsgroup.nospam> wrote in message
news:2F**********************************@microsof t.com...
I used
HttpContext.Current.Cache["Categories"] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Current.Cache["Categories"] == null ) {
HttpContext.Current.Cache["Categories"] = GetCategoriesFromDB();
}
return (DataView)HttpContext.Current.Cache["Categories"];}

However when database data changed, the page still keept the cached data
no
matter how many times I refresh the page. I closed the browser, and
reopened
it, and it had no effect. Finally I restarted the machine, the data then
refreshed. Is that the correct way for ASPNET cache work?


Nov 19 '05 #6
You're welcome :-)

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

--------------------
| Thread-Topic: ASPNET cache cannot refresh
| thread-index: AcWC9DvqzHvzcR6hQQW2FfwztoqTtg==
| X-WBNR-Posting-Host: 216.64.114.162
| From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgroup.nospam>
| References: <2F**********************************@microsoft.co m>
<#T**************@TK2MSFTNGP09.phx.gbl>
| Subject: Re: ASPNET cache cannot refresh
| Date: Thu, 7 Jul 2005 06:03:13 -0700
| Lines: 42
| Message-ID: <95**********************************@microsoft.co m>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="Utf-8"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Content-Class: urn:content-classes:message
| Importance: normal
| Priority: normal
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.0
| Newsgroups: microsoft.public.dotnet.framework.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.phx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.phx.gbl!TK2MSFTNGXA03.phx.gbl
| Xref: TK2MSFTNGXA01.phx.gbl
microsoft.public.dotnet.framework.aspnet:110902
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet
|
| Thanks guys, It is very helpful. Charts
|
| "Lars-Erik Aabech" wrote:
|
| > Hi!
| >
| > If you use the HttpContext.Current.Cache.Add(...) method instead, you
can
| > specify the length of time before the cached object is reset. See the
| > documentation here:
| >
http://msdn.microsoft.com/library/en...webcachingcach
eclassaddtopic.asp?frame=true
| >
| > If you only set the item by using the indexer, you cache the item
forever or
| > until the application is reset.
| > You could, however, write some code in the page that updates the data,
that
| > resets the cache object again. That would keep the cache syncronized at
all
| > times.
| >
| > HTH,
| > Lars-Erik
| >
| > "Charts" <Ac*****@newsgroup.nospam> wrote in message
| > news:2F**********************************@microsof t.com...
| > >I used
| > > HttpContext.Current.Cache["Categories"] To cache data from database.
| > > The code is like that.
| > >
| > > public static DataView GetCategories() {
| > > if ( HttpContext.Current.Cache["Categories"] == null ) {
| > > HttpContext.Current.Cache["Categories"] = GetCategoriesFromDB();
| > > }
| > > return (DataView)HttpContext.Current.Cache["Categories"];}
| > >
| > > However when database data changed, the page still keept the cached
data
| > > no
| > > matter how many times I refresh the page. I closed the browser, and
| > > reopened
| > > it, and it had no effect. Finally I restarted the machine, the data
then
| > > refreshed. Is that the correct way for ASPNET cache work?
| > >
| >
| >
| >
|

Nov 19 '05 #7

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

Similar topics

3
by: Bite My Bubbles | last post by:
I found the answer! It is a IIS 6 /ASP problem http://support.microsoft.com/default.aspx?scid=kb;en-us;332075
4
by: Jo Gradeless | last post by:
There appears to be plenty of discussion in newsgroups on how to do caching but nothing on why I'm in some disagreement with one of my colleagues over the use of caching of webpages. He...
4
by: Erick | last post by:
i have an asp.net application and I want to save the results of an sql query in cache. Because the queries take 28 seconds to run (there are twelve similar queries) I want to run it all at 4am, ...
16
by: JCauble | last post by:
We have a large Asp.net application that is currently crashing our production servers. What we are seeing is the aspnet_wp eat up a bunch of memory and then stop unexpectedly. Does not recycle. ...
0
by: Evgeny | last post by:
I'm trying to do server caching for some pages of a website I developed. All the pages include the same user control to which they pass a parameter. In this user control I have the following 4...
0
by: Will Holley | last post by:
I have a problem with cache headers which I cannot track down. We are running IIS6 on Windows Server 2003 and ASP.NET 2.0. Our application has an installer which sets up our caching options in...
3
by: Raj | last post by:
I created a refresh deferred MQT, and during full refresh there were 4 or 5 lock waits, all waiting on a 'S' lock on Internal Catalog Cache ? Can some one explain how to prevent this from happening?
0
by: Dinesh | last post by:
Hi , Trying to speed up the cache refresh time.... Assumptions: Configurations in the web.config file are done and also Sqldependency is set between the application and the database table. ...
2
by: jld | last post by:
Hi, I developed an asp.net based eCommerce Website for a client and it is hosted at discount asp. The site is quite interactive, queries a database a lot and uses ajax.asp.net to spice up...
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
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

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.