473,606 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASPNET cache cannot refresh

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

public static DataView GetCategories() {
if ( HttpContext.Cur rent.Cache["Categories "] == null ) {
HttpContext.Cur rent.Cache["Categories "] = GetCategoriesFr omDB();
}
return (DataView)HttpC ontext.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 1980
Hi!

If you use the HttpContext.Cur rent.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*****@newsgr oup.nospam> wrote in message
news:2F******** *************** ***********@mic rosoft.com...
I used
HttpContext.Cur rent.Cache["Categories "] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Cur rent.Cache["Categories "] == null ) {
HttpContext.Cur rent.Cache["Categories "] = GetCategoriesFr omDB();
}
return (DataView)HttpC ontext.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*****@newsgr oup.nospam> wrote in message
news:2F******** *************** ***********@mic rosoft.com...
I used
HttpContext.Cur rent.Cache["Categories "] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Cur rent.Cache["Categories "] == null ) {
HttpContext.Cur rent.Cache["Categories "] = GetCategoriesFr omDB();
}
return (DataView)HttpC ontext.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.Cac he.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******@newsg roup.nospam>
| From: "Lars-Erik Aabech" <la******@newsg roup.nospam>
| References: <2F************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: host-81-191-131-56.bluecom.no 81.191.131.56
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GP08.phx.gbl!TK 2MSFTNGP09.phx. gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1106 51
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Hi!
|
| If you use the HttpContext.Cur rent.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*****@newsgr oup.nospam> wrote in message
| news:2F******** *************** ***********@mic rosoft.com...
| >I used
| > HttpContext.Cur rent.Cache["Categories "] To cache data from database.
| > The code is like that.
| >
| > public static DataView GetCategories() {
| > if ( HttpContext.Cur rent.Cache["Categories "] == null ) {
| > HttpContext.Cur rent.Cache["Categories "] = GetCategoriesFr omDB();
| > }
| > return (DataView)HttpC ontext.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*****@newsgr oup.nospam> wrote in message
news:2F******** *************** ***********@mic rosoft.com...
I used
HttpContext.Cur rent.Cache["Categories "] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Cur rent.Cache["Categories "] == null ) {
HttpContext.Cur rent.Cache["Categories "] = GetCategoriesFr omDB();
}
return (DataView)HttpC ontext.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.Cur rent.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*****@newsgr oup.nospam> wrote in message
news:2F******** *************** ***********@mic rosoft.com...
I used
HttpContext.Cur rent.Cache["Categories "] To cache data from database.
The code is like that.

public static DataView GetCategories() {
if ( HttpContext.Cur rent.Cache["Categories "] == null ) {
HttpContext.Cur rent.Cache["Categories "] = GetCategoriesFr omDB();
}
return (DataView)HttpC ontext.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: AcWC9DvqzHvzcR6 hQQW2FfwztoqTtg ==
| X-WBNR-Posting-Host: 216.64.114.162
| From: =?Utf-8?B?Q2hhcnRz?= <Ac*****@newsgr oup.nospam>
| References: <2F************ *************** *******@microso ft.com>
<#T************ **@TK2MSFTNGP09 .phx.gbl>
| Subject: Re: ASPNET cache cannot refresh
| Date: Thu, 7 Jul 2005 06:03:13 -0700
| Lines: 42
| Message-ID: <95************ *************** *******@microso ft.com>
| 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.publi c.dotnet.framew ork.aspnet
| NNTP-Posting-Host: TK2MSFTNGXA03.p hx.gbl 10.40.2.250
| Path: TK2MSFTNGXA01.p hx.gbl!TK2MSFTN GXA03.phx.gbl
| Xref: TK2MSFTNGXA01.p hx.gbl
microsoft.publi c.dotnet.framew ork.aspnet:1109 02
| X-Tomcat-NG: microsoft.publi c.dotnet.framew ork.aspnet
|
| Thanks guys, It is very helpful. Charts
|
| "Lars-Erik Aabech" wrote:
|
| > Hi!
| >
| > If you use the HttpContext.Cur rent.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*****@newsgr oup.nospam> wrote in message
| > news:2F******** *************** ***********@mic rosoft.com...
| > >I used
| > > HttpContext.Cur rent.Cache["Categories "] To cache data from database.
| > > The code is like that.
| > >
| > > public static DataView GetCategories() {
| > > if ( HttpContext.Cur rent.Cache["Categories "] == null ) {
| > > HttpContext.Cur rent.Cache["Categories "] = GetCategoriesFr omDB();
| > > }
| > > return (DataView)HttpC ontext.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
32837
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
2685
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 states that " I really do not expect to have to click my refresh button on modern day sites. Years ago when amateur web building was all the rage it was quite common to have to refresh."
4
4365
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, Place the results in cache and use those values the rest of the day for all users. I have something like this CallMe = New Caching.CacheItemRemovedCallback(AddressOf Refresh)
16
2380
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. Example: After about 5 hours with a concurrent user base of about 150 users the application raises the aspnet_wp memory usage by almost 500MB. If our server guys modify the web.config this data is released and the workerprocess goes back to a...
0
1137
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 lines. Response.Cache.SetValidUntilExpires(true); Response.Cache.SetCacheability(HttpCacheability.Server); Response.Cache.SetExpires(DateTime.Now.AddDays(7)); Response.Cache.VaryByParams = true;
0
2157
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 the metabase - specifically it sets HttpExpires="D, 0" and CacheControlCustom="no-cache" on the directory containing our web forms. In IIS manager this shows up correctly (saying expires immediately). For some specific web forms (aspx) within...
3
6627
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
1245
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. Actual Flow: Whenever I do some manipulations(insert,update) on the the
2
2456
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 interactivity. The service suffers from a lot of restarts since discountasp enforces a 100mb per worker thread limit and when you top it, the service gets restarted. When there is a lot of traffic on the site, this happens
0
8449
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8432
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...
0
8310
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...
0
6781
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
5968
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
5466
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();...
0
3942
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2451
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
0
1305
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.