Create a gist now

Instantly share code, notes, and snippets.

CacheCow.Client sample. Requires CacheCow.Client v>=0.1.3
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