RestClient getting old data, how to clear cache?

4,257 views
Skip to first unread message

Ski

unread,
May 11, 2012, 12:32:03 PM5/11/12
to RestSharp
Hi, I'm using RestClient to consume RackSpace's Rest web service. One
of my methods needs to keep polling the web service for the current
progress of a routine, and then do something when it is finished. The
problem I'm having is that every time I poll the server, I'm getting
the same (old) data. Does RestSharp use a cache? Is there a method to
clear it?

This is my code for polling the current progress:
var client = new RestClient(cmdURI);
client.ClearHandlers(); <-- This was a guess, I thought it
might clear the cache
string resource = "/images/"+imageID;
var request = new RestRequest(resource, Method.GET);
request.AddHeader("X-Auth-Token", authToken);

RestResponse response =
(RestResponse)client.Execute(request);

I run that code inside a while loop:

while (imageFinished == false)
{
image = imageCreationStatus(cmdURI, authToken,
newImageID);
imageStatus = image.status;
if (imageStatus == "ACTIVE")
imageFinished = true;
else
{
listBox1.Items.Add("image creation progress:
"+image.progress);
System.Threading.Thread.Sleep(10000);
}
}
MessageBox.Show("Image Created!");

What I see is listBox1 filling up with 'image creation progress: 0",
and even after the image is finished (I can verify using RackSpace's
web gui), it continues in an infinite loop saying it is currently 0.

Thanks,

Ronan

Cristovão Morgado

unread,
May 11, 2012, 1:26:05 PM5/11/12
to rest...@googlegroups.com
just send a quuerystring random...
sometimes it's the end server that caches using the URL

cmdURI +"?timestamp"+ datetime.now().tostring() 

something like that
--
Cristovao Morgado
@TheSaintr


Peter Johanson

unread,
May 11, 2012, 2:24:58 PM5/11/12
to rest...@googlegroups.com
RestSharp uses System.Net.WebRequest/HttpWebReqest under the hood for
its requests, so it should be respecting
HttpWebRequest.DefaultCachePolicy regarding caching.

Have you tried inspecting the traffic using either Fiddler or Wireshark?
Often this can be very revealing about what the actual HTTP traffic
looks like.

-pete
--

Ski

unread,
May 11, 2012, 2:50:28 PM5/11/12
to RestSharp
Thanks Cristavo, that worked! I just added the current timestamp to
the resource string (i.e. the end of the url)

On May 11, 1:26 pm, Cristovão Morgado <cristovao.morg...@gmail.com>
wrote:

Ski

unread,
May 11, 2012, 2:55:29 PM5/11/12
to RestSharp
Pete,

I haven't tried inspecting the traffic(I've never used one of those
tools), I'll take a look, thanks.

-Ronan

Andrew Young

unread,
May 11, 2012, 4:27:24 PM5/11/12
to rest...@googlegroups.com
Are you working behind a proxy?

Ski

unread,
May 12, 2012, 5:55:50 PM5/12/12
to RestSharp
Andrew,

Nope, no proxy.
Reply all
Reply to author
Forward
0 new messages