How to cache a json xamarin iOS request

0

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;
    } 
    
asked by anonymous 26.06.2018 / 12:07

0 answers