public async Task <MusicBrainsJsonModel> GetMusicBrainzData(string mbId, CancellationToken cancellationToken) { cancellationToken.ThrowIfCancellationRequested(); if (string.IsNullOrEmpty(mbId)) { throw new ArgumentNullException(nameof(mbId)); } var cachedMusicBrainzData = _cacheHelper.GetFromCache <MusicBrainsJsonModel>($"MusicBrainz_{mbId}"); if (cachedMusicBrainzData != null) { return(cachedMusicBrainzData); } var baseUrl = _configuration.GetValue <string>("ApiUrls:MusicBrainz").Replace("{mbId}", mbId); try { var client = new RestClient(baseUrl) { Timeout = -1 }; var response = await client.ExecuteGetAsync <MusicBrainsJsonModel>(new RestRequest(Method.GET), cancellationToken); if (response.Data != null) { _cacheHelper.AddToCache($"MusicBrainz_{mbId}", response.Data, TimeSpan.FromDays(1)); return(response.Data); } } catch (Exception e) { _logger.LogError(e, e.Message); throw; } return(null); }
public string ReadFileContents(string filePath) { if (_cache.GetCachedItem(filePath) != null) { return((string)_cache.GetCachedItem(filePath)); } string stringData; using (var schameReader = File.OpenText(filePath)) stringData = schameReader.ReadToEnd(); var fileContent = Regex.Replace(stringData, @"\\", @"\\"); _cache.AddToCache(filePath, fileContent); return(fileContent); }