public IActionResult Listar() { IEnumerable <Perfil> perfis; bool cacheEstaConfigurado = new Func <bool>(() => { try { return(_cache.GetString("ListaPerfis") != null); } catch { return(false); } })(); if (cacheEstaConfigurado) { string valorEmCache = _cache.GetString("ListaPerfis"); if (string.IsNullOrWhiteSpace(valorEmCache)) { perfis = _perfilService.ListarTodos(); _cache.SetString("ListaPerfis", JsonConvert.SerializeObject(perfis), _cacheOptions); } else { perfis = JsonConvert.DeserializeObject <IEnumerable <Perfil> >(valorEmCache); } } else { perfis = _perfilService.ListarTodos(); } if (perfis == null) { return(NotFound()); } return(Ok(perfis)); }