0
I’d like to know how to do cache of a request Httpclient whose return is a json and determine the amount of storage days of that cache.
public async Task<List<Categoria>> GetCategorias(){
string URL = string.Format(Constants.apiURL, "ProdutoCategoria/Obter");
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders
.Accept
.Add(new MediaTypeWithQualityHeaderValue("application/json"));
var response = await httpClient.GetAsync(URL);
var content = await response.Content.ReadAsStringAsync();
Debug.WriteLine(content);
List<Categoria> listaCat = new List<Categoria>();
try
{
var jsonRetorno = JsonConvert.DeserializeObject<List<Categoria>>(content);
foreach (var item in jsonRetorno)
{
listaCat.Add(item);
}
}catch(Exception e){
Debug.WriteLine("Ocorreu um erro: ", e.Message);
}
return listaCat;
}
I have never directly used any tool for caching like this. I don’t even know if it has. The implementation of a cache also doesn’t seem to be a bug-in-the-woods... It just wasn’t clear if the cache would be on the server or client side.
– Diego Rafael Souza
@Diegorafaelsouza would be on the client side Diego.
– Bruno Richart
@Brunorichart, which version of . Net?
– Leandro Angelo
@Leandroangelo version is 2.1.301
– Bruno Richart