public MemoryCacheStrategy(int cacheExpirationMinutes, IDataFileLoader dataFileLoader, IMemoryCache memoryCache) : this(memoryCache, new MemoryCacheEntryOptions()) { _memoryCacheEntryOptions.AbsoluteExpirationRelativeToNow = new TimeSpan(hours: 0, minutes: cacheExpirationMinutes, seconds: 0); _dataFileLoader = dataFileLoader; _postEvictionDelegate = new PostEvictionDelegate((key, value, reason, state) => { if (reason == EvictionReason.Expired) { _dataFileLoader.LoadFileAsync <T>(overwrite: true); } }); _memoryCacheEntryOptions.RegisterPostEvictionCallback(_postEvictionDelegate); }
private async Task <List <T> > loadDataFileAsync <T>(Func <string, Task> progressHandlerAsync, bool downloadFilesFromWeb) { string dataFilePath = Path.Combine(rootFilePath, "Data Files"); string imageFilePath = Path.Combine(rootFilePath, "Images"); IDataFileLoader loader = loaders.Single(l => l.LoaderType == typeof(T)); List <T> items = await loader.LoadFromDataFileAsync <T>(dataFilePath, imageFilePath, downloadFilesFromWeb); if (progressHandlerAsync != null) { await progressHandlerAsync(loader.LoaderName); } return(items); }
public AircraftRepository(IDataFileLoader loader, IMemoryCache memoryCache) : base(loader, memoryCache) { }
public RouteRepository(IDataFileLoader loader, IMemoryCache memoryCache) : base(loader, memoryCache) { }
public DataAccessFactory(HttpClient httpClient, IMemoryCache memoryCache) { _memoryCache = memoryCache; _dataFileLoader = new DataFileLoader(httpClient); _dataFileLoader.LoadAllFilesAsync().Wait(); }
public RepositoryBase(IDataFileLoader dataFileLoader, IMemoryCache memoryCache) { _cache = new CacheBase <T>(new MemoryCacheStrategy <T>(OpenFligthsConstants.EXPIRY_MINUTES, dataFileLoader, memoryCache)); _dataFileLoader = dataFileLoader; }