Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Stop XmlDocument.Load() from using cached data?

18 views
Skip to first unread message

Mahmoud Al-Qudsi

unread,
May 9, 2008, 4:36:29 PM5/9/08
to
Is there any way to stop an XmlDocument object from using data grabbed
from a previous request?

e.g. if I used XmlDocument.Load to grab a URI, and I know that this
URI changes often (for example, an RSS feed) can I somehow tell the
framework to not use cached data?

Will I have to create a custom HttpWebRequest and convert the data to
an XmlDocument for processing or is there some way to tell XmlDocument
(perhaps via the XmlResolver somehow?) to never use the cache?

Thanks.

Anthony Jones

unread,
May 9, 2008, 6:09:49 PM5/9/08
to

"Mahmoud Al-Qudsi" <mqu...@gmail.com> wrote in message
news:e1118045-cc1f-4768...@y21g2000hsf.googlegroups.com...

The Load method honors the WebRequest Caching policy which by default is set
to bypass the cache. However its worth noting that this actually means
bypass the local cache it does not add a pragma: no-cache header to the
request and therefore other caches such as a proxy server between the client
and the origin server may serve content from a cache.

You will need to use HttpWebRequest if the default behaviour (or your
prevailing settings set via the requestCaching element in the .config(s)) is
not want you need.

I suggest you use a policy created wth Revalidate level.


--
Anthony Jones - MVP ASP/ASP.NET


Mahmoud Al-Qudsi

unread,
May 9, 2008, 6:19:30 PM5/9/08
to

> You will need to use HttpWebRequest if the default behaviour (or your
> prevailing settings set via the requestCaching element in the .config(s)) is
> not want you need.
>
> I suggest you use a policy created wth Revalidate level.

I take it this will this do the trick then?

....
WebRequest.DefaultCachePolicy = new
RequestCachePolicy(RequestCacheLevel.Revalidate);
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.Load(myUri);

Anthony Jones

unread,
May 10, 2008, 4:04:11 PM5/10/08
to
"Mahmoud Al-Qudsi" <mqu...@gmail.com> wrote in message
news:6c6352fc-79bf-4139...@t54g2000hsg.googlegroups.com...

Assuming you don't have a conflicting setting in the application's config(s)
then yes that should do it.

Mahmoud Al-Qudsi

unread,
May 11, 2008, 3:06:24 PM5/11/08
to

> Assuming you don't have a conflicting setting in the application's config(s)
> then yes that should do it.

Thanks, it worked great.

Anthony Jones

unread,
May 11, 2008, 5:05:48 PM5/11/08
to
"Mahmoud Al-Qudsi" <mqu...@gmail.com> wrote in message
news:1195a8ef-2e45-4498...@m3g2000hsc.googlegroups.com...

Perhaps I should have mentioned in response to your previous reply that
modifying the DefaultCachePolicy as you are doing there affects _all_ Web
Client code. This may have some un-wanted side effects in previously
working code.

Since any code in the app domain can muck about with the DefaultCachePolicy
its actually not a good idea to change it or rely on it. I think the best
approach is to use an instance of HttpWebRequest and set the policy of that
instance.

0 new messages