예제 #1
0
        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();
            }
        }
예제 #2
0
 public JsonPlaceholderImportExport(IJsonPlaceholderRepository importRepository, IFileExportRepository fileExportRepository,
                                    ILogger <JsonPlaceholderImportExport> logging, AppSettings appSettings)
 {
     _importRepository     = importRepository;
     _fileExportRepository = fileExportRepository;
     _logging     = logging;
     _appSettings = appSettings;
 }
예제 #3
0
        public JsonPlaceholderRepositoryCacheDecorator(IJsonPlaceholderRepository repository, ILogger logger)
        {
            _repository = repository;
            _logger     = logger;

            if (!_cached)
            {
                PrimeCache(_repository, _logger);
            }
        }