Created
August 6, 2012 21:57
-
-
Save aliostad/3278821 to your computer and use it in GitHub Desktop.
CacheCow.Client sample. Requires CacheCow.Client v>=0.1.3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using System.Net.Http; | |
using System.Net.Http.Headers; | |
using CacheCow.Client; | |
using CacheCow.Client.Headers; | |
namespace ConsoleApplication1 | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var client = new HttpClient(new CachingHandler() | |
{ | |
InnerHandler = new HttpClientHandler() | |
} | |
); | |
var initialResponse = client.GetAsync("http://carmanager.azurewebsites.net/api/Car/5").Result; | |
var initialResponseHeader = initialResponse.Headers.Single(x => x.Key == CacheCowHeader.Name).Value.First(); | |
Console.WriteLine(initialResponse.Headers.ETag.Tag); | |
Console.WriteLine(initialResponseHeader); | |
var secondResponse = client.GetAsync("http://carmanager.azurewebsites.net/api/Car/5").Result; | |
var secondResponseHeader = secondResponse.Headers.Single(x => x.Key == CacheCowHeader.Name).Value.First(); | |
Console.WriteLine(secondResponseHeader); | |
var nocacheRequest = new HttpRequestMessage(HttpMethod.Get, | |
"http://carmanager.azurewebsites.net/api/Car/5"); | |
nocacheRequest.Headers.CacheControl = new CacheControlHeaderValue() | |
{ | |
NoCache = true | |
}; | |
var nocacheResponse = client.SendAsync(nocacheRequest).Result; | |
var nocacheResponseHeader = nocacheResponse.Headers.FirstOrDefault( | |
x => x.Key == CacheCowHeader.Name); | |
Console.WriteLine(nocacheResponseHeader); | |
Console.Read(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment