By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

ASPNET cache cannot refresh

P: n/a
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
Share this Question
Share on Google+
6 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.