I am using RestSharp to call Web Api repeatedly for all CRUD operations. Now what I am doing it that RestClient ends up getting wrapped into caching object. Is this bad / causing it to be slow?
public class ReferenceDS:IReferenceDS
{
private static readonly RestClient Client = AppConfiguration.RestClient();
private static readonly string apiPath = "api/Reference/";
public List<AcademicLevel> GetAcademicLevels()
{
var request = new RestRequest(apiPath + "GetAcademicLevels", Method.GET) { RequestFormat = DataFormat.Json };
var response = Client.Execute<List<AcademicLevel>>(request);
return response.Data;
}
public List<Content> GetContent()
{
var request = new RestRequest(apiPath + "GetContent", Method.GET) { RequestFormat = DataFormat.Json };
var response = Client.Execute<List<Content>>(request);
return response.Data;
}
//.......
}
Now you see that AppConfiguration is called
This is what I am doing
public static RestClient RestClient() {
ObjectCache cache = MemoryCache.Default;
if (cache["RestClient"] == null)
{
string url = GetAppSetting("WebAPIurl");
var policy = new CacheItemPolicy { AbsoluteExpiration = DateTimeOffset.Now.AddMinutes(CacheExpireMinutes()) };
RestClient client = new RestClient(url);
cache.Add("RestClient", client, policy);
}
return (RestClient)cache["RestClient"];
}
Is this bad way to be doing this? ObjectCache / MemoryCache / CacheItemPolicy etc.. ?