Reputation: 47
I have a console app that needs to dynamically load all the endpoints in my API app and get the details of the data that is cached.
foreach (var routeTemplate in listRouteTempplates)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://localhost/appName/" + routeTemplate );
WebResponse response = null;
Stream dataStream = null;
request.Method = HttpMethod.Get.ToString();
response = request.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
responseFromServer = reader.ReadToEnd();
reader.Close();
dataStream.Close();
response.Close();
var count=HttpRuntime.Cache.Count;
}
When invoking each endpoint, the data retrieved is also cached. I confirmed that by calling the endpoints directly (via postman) and checking the cache.
But in the console app, even though the response does have the correct data, the count of items in HttpRuntime.Cache is always zero.
Is there a reason the data is not cached when I call the endpoints in a console app ?
Thanks
Upvotes: 1
Views: 759
Reputation: 1038840
The cache in which items are stored lives on the server inside your Web API host. It is then normal that the cache instance that you are checking inside your client console application doesn't have any items in it - those are 2 completely different object instances living in 2 different applications.
Upvotes: 4