I have mvc / c# / razor app that using the following method / class and I found out our developer put this on Views/Shared/Layoutpage.
It looks like it is called this method everytime when the page is refreshed. As a result, it is super easy to max out the API usage.
My question is: What is the best practice to use cache in c# to reduce this usage? In general, the layoutpage will be loaded as usual.
Please show me how it works in codes/c#. Thanks
public static string GetLatitiudeByIP(string ip)
{
string returnValue = "34.028623";
XmlDocument foo = new XmlDocument();
foo.Load(String.Format("
http://api.ipstack.com/" + ip + "?access_key=7efaasdfasdfa
sdfadsf382
9ad25d56ab
30492c9c79
d24f1&outp
ut=xml&leg
acy=1"));
XmlNode latitudeNode = foo.SelectSingleNode("/res
ult/latitu
de");
if(latitudeNode != null)
{
returnValue = latitudeNode.InnerText;
}
return returnValue;
}