[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB.net Webclient - trying not to cache webpage

Posted on 2015-02-12
4
Medium Priority
?
230 Views
Last Modified: 2015-03-06
The main thing I am trying to do is get page load time of a website.  But it seems to work the first time I put a new website domain in, but run it again it appears to be a lot faster (cache). I dont want that, I want it make sure it does not load cache version.  Any ideas on what I did wrong below?  I'm also open to a better way to get total page load time.

Dim sw = New Stopwatch()
sw.Start()
Dim policy As New RequestCachePolicy(RequestCacheLevel.NoCacheNoStore)
Dim sourceString As String = New System.Net.WebClient().DownloadString("http://www.google.com")

 sw.Stop()
 Dim ts As TimeSpan = sw.Elapsed
        txtWebSource.Text = sourceString
        ' Format and display the TimeSpan value. 
        Dim elapsedTime As String = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", ts.Hours, ts.Minutes, ts.Seconds, ts.Milliseconds / 1)
        lblPingTime.Text = elapsedTime

Open in new window

0
Comment
Question by:keith1001
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 36

Expert Comment

by:Kimputer
ID: 40605340
You didn't actually use the policy. Make sure WebClient.CachePolicy is used in your code.

Please note that the numbers AFTER the first run are pretty accurate, even if you DIDN'T use the policy (I only mentioned you didn't use it so in your further .net programming, setting a variable and not using it later is senseless). Cache isn't used (you can capture your network traffic, you will see it is indeed reloaded from the server every time).
Since you used a quick website, you would think it's not accurate. If you tested on a foreign slow website, you probably wouldn't notice it.
Why the first run is always a bit higher has probably something to do with the .Net framework.
0
 

Author Comment

by:keith1001
ID: 40607298
I have tested it on bigger sites, and the 1st run is always longer by a couple seconds.

So what do I need to add the set the policy to NoCache or Reload?
0
 
LVL 36

Accepted Solution

by:
Kimputer earned 2000 total points
ID: 40607559
Read my message again. I said even if you didn't use the policy, the results will largely STILL be the same (first run longer). You should discard the first result, it's a .NET thing. All subsequent timings are correct.
So Policy to NoCache, Reload or NOT SETTING it, it doesn't matter. Your application WILL get the files from the server, NOT from disk or memory.
0
 

Author Closing Comment

by:keith1001
ID: 40650492
Sorry for long time for accepting, fighting some health issues unfortunately.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: jpaulino
XML Literals are a great way to handle XML files and the community doesn’t use it as much as it should.  An XML Literal is like a String (http://msdn.microsoft.com/en-us/library/system.string.aspx) Literal, only instead of starting and ending with w…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question