private static void PrimeCache(IJsonPlaceholderRepository repository, ILogger logger) { _lock.Wait(); try { if (!_cached) { Parallel.Invoke( () => { logger.Verbose("Priming Typicode users cache."); _cachedUsers = repository.GetUsersAsync().GetAwaiter().GetResult().ToList(); }, () => { logger.Verbose("Priming Typicode albums cache."); _cachedAlbums = repository.GetAlbumsAsync().GetAwaiter().GetResult().ToList(); }); _cached = true; } } finally { _lock.Release(); } }
public JsonPlaceholderImportExport(IJsonPlaceholderRepository importRepository, IFileExportRepository fileExportRepository, ILogger <JsonPlaceholderImportExport> logging, AppSettings appSettings) { _importRepository = importRepository; _fileExportRepository = fileExportRepository; _logging = logging; _appSettings = appSettings; }
public JsonPlaceholderRepositoryCacheDecorator(IJsonPlaceholderRepository repository, ILogger logger) { _repository = repository; _logger = logger; if (!_cached) { PrimeCache(_repository, _logger); } }