3

I have a simple question, that I can't find a straight answer:

Does RestSharp cache request made? If it does, how much time does the cache last and how can i change it? If it doesn't, how can I add cache to RestSharp?

I'm using it in an Asp.net MVC app deployed to Azure web application.

Thanks for any help.

Hugo Alves
  • 1,555
  • 2
  • 18
  • 41
  • 1
    What makes you think it does? – George Stocker Apr 18 '16 at 10:50
  • @GeorgeStocker apparently it does under the hood, based on codeCaster's answer – Hugo Alves Apr 18 '16 at 11:06
  • I'm trying to ask you show an example of a request that is cached that you didn't expect to be but was. Right now it all depends on how your app is set up. – George Stocker Apr 18 '16 at 11:30
  • 1
    unfortunately due to my lack of knowledge on this i don't know how to see if a request was using cache or not. I was asking this because i want to increase the duration of the cache. From what i've searched i haven't found anywhere the duration of the cache nor how to change it. – Hugo Alves Apr 18 '16 at 11:38

2 Answers2

4

RestSharp doesn't cache by itself, but under the hood the framework classes it uses do, through WinInet.

You can bypass this cache with conditional requests, or by adding a cache buster to the query string.

This all is influenced by the Cache Policy, see MSDN: Cache Policy.

See also How to clear the cache of HttpWebRequest, WP7 - Prevent RestSharp from caching, Refreshing in RestSharp for Windows Phone and so on.

Community
  • 1
  • 1
CodeCaster
  • 147,647
  • 23
  • 218
  • 272
  • in fact i want to provably increase the cache duration. – Hugo Alves Apr 18 '16 at 11:04
  • 2
    Then see the WinInet documentation and the [Cache Policy documentation](https://msdn.microsoft.com/en-us/library/0eywff03(v=vs.110).aspx) that abstracts this functionality. – CodeCaster Apr 18 '16 at 11:05
  • i've been looking into HttpRequestCachePolicy, but restsharp doesn't allow you to set cache policies. i have the nuget version 105.1.0 – Hugo Alves Apr 19 '16 at 09:50
4

https://github.com/restsharp/RestSharp/issues/401

var client = new RestClient("http://example.com");
client.CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.Revalidate);
Kaven Wu
  • 51
  • 4