I would like to know how to cache a request HttpClient whose return is a json and determine the number of storage days for 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;
}