private ImagePipelineConfig(Builder builder) { _animatedImageFactory = builder.AnimatedImageFactory; _bitmapMemoryCacheParamsSupplier = builder.BitmapMemoryCacheParamsSupplier ?? new DefaultBitmapMemoryCacheParamsSupplier(); _bitmapConfig = builder.BitmapConfig == default(BitmapPixelFormat) ? BitmapPixelFormat.Bgra8 : builder.BitmapConfig; _cacheKeyFactory = builder.CacheKeyFactory ?? DefaultCacheKeyFactory.Instance; _decodeMemoryFileEnabled = builder.IsDecodeMemoryFileEnabled; _fileCacheFactory = builder.FileCacheFactory ?? new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory()); _downsampleEnabled = builder.IsDownsampleEnabled; _encodedMemoryCacheParamsSupplier = builder.EncodedMemoryCacheParamsSupplier ?? new DefaultEncodedMemoryCacheParamsSupplier(); _imageCacheStatsTracker = builder.ImageCacheStatsTracker ?? NoOpImageCacheStatsTracker.Instance; _imageDecoder = builder.ImageDecoder; _isPrefetchEnabledSupplier = builder.IsPrefetchEnabledSupplier ?? new SupplierImpl <bool>( () => { return(true); }); _mainDiskCacheConfig = builder.MainDiskCacheConfig ?? GetDefaultMainDiskCacheConfig(); _memoryTrimmableRegistry = builder.MemoryTrimmableRegistry ?? NoOpMemoryTrimmableRegistry.Instance; _networkFetcher = builder.NetworkFetcher ?? new HttpUrlConnectionNetworkFetcher(); _platformBitmapFactory = builder.PlatformBitmapFactory; _poolFactory = builder.PoolFactory ?? new PoolFactory(PoolConfig.NewBuilder().Build()); _progressiveJpegConfig = builder.ProgressiveJpegConfig == default(IProgressiveJpegConfig) ? new SimpleProgressiveJpegConfig() : builder.ProgressiveJpegConfig; _requestListeners = builder.RequestListeners ?? new HashSet <IRequestListener>(); _resizeAndRotateEnabledForNetwork = builder.ResizeAndRotateEnabledForNetwork; _smallImageDiskCacheConfig = builder.SmallImageDiskCacheConfig ?? _mainDiskCacheConfig; // Below this comment can't be built in alphabetical order, because of dependencies int numCpuBoundThreads = _poolFactory.FlexByteArrayPoolMaxNumThreads; _executorSupplier = builder.ExecutorSupplier ?? new DefaultExecutorSupplier(numCpuBoundThreads); _imagePipelineExperiments = builder.Experiment.Build(); }
public void Initialize() { // Initializes the IFileCache _fileCacheFactory = new DiskStorageCacheFactory(new DynamicDefaultDiskStorageFactory()); _fileCache = _fileCacheFactory.Get(DiskCacheConfig.NewBuilder().Build()); // Initializes the IPooledByteBufferFactory and PooledByteStreams _poolFactory = new PoolFactory(PoolConfig.NewBuilder().Build()); _byteBufferFactory = _poolFactory.PooledByteBufferFactory; _pooledByteStreams = _poolFactory.PooledByteStreams; // Initializes the IPooledByteBuffer from an image var file = StorageFile.GetFileFromApplicationUriAsync( new Uri("ms-appx:///Assets/SplashScreen.scale-200.png")).GetAwaiter().GetResult(); using (var stream = file.OpenReadAsync().GetAwaiter().GetResult()) { _pooledByteBuffer = _byteBufferFactory.NewByteBuffer( ByteStreams.ToByteArray(stream.AsStream())); } _closeableReference = CloseableReference <IPooledByteBuffer> .of(_pooledByteBuffer); _encodedImage = new EncodedImage(_closeableReference); _stagingArea = StagingArea.Instance; _imageCacheStatsTracker = NoOpImageCacheStatsTracker.Instance; // Initializes the cache keys IList <ICacheKey> keys = new List <ICacheKey>(); keys.Add(new SimpleCacheKey("http://test.uri")); keys.Add(new SimpleCacheKey("http://tyrone.uri")); keys.Add(new SimpleCacheKey("http://ian.uri")); _cacheKey = new MultiCacheKey(keys); // Initializes the executors _isCancelled = new AtomicBoolean(false); _readPriorityExecutor = Executors.NewFixedThreadPool(1); _writePriorityExecutor = Executors.NewFixedThreadPool(1); // Initializes the disk cache _bufferedDiskCache = new BufferedDiskCache( _fileCache, _byteBufferFactory, _pooledByteStreams, _readPriorityExecutor, _writePriorityExecutor, _imageCacheStatsTracker); }
/// <summary> /// Instantiates the <see cref="BufferedDiskCache"/>. /// </summary> public BufferedDiskCache( IFileCache fileCache, IPooledByteBufferFactory pooledByteBufferFactory, PooledByteStreams pooledByteStreams, IExecutorService readExecutor, IExecutorService writeExecutor, IImageCacheStatsTracker imageCacheStatsTracker) { _fileCache = fileCache; _pooledByteBufferFactory = pooledByteBufferFactory; _pooledByteStreams = pooledByteStreams; _readExecutor = readExecutor; _writeExecutor = writeExecutor; _imageCacheStatsTracker = imageCacheStatsTracker; _stagingArea = StagingArea.Instance; }
/// <summary> /// Instantiates the <see cref="BufferedDiskCache"/>. /// </summary> public BufferedDiskCache( IFileCache fileCache, IPooledByteBufferFactory pooledByteBufferFactory, PooledByteStreams pooledByteStreams, IExecutorService readExecutor, IExecutorService writeExecutor, IImageCacheStatsTracker imageCacheStatsTracker) { _fileCache = fileCache; _pooledByteBufferFactory = pooledByteBufferFactory; _pooledByteStreams = pooledByteStreams; _readExecutor = readExecutor; _writeExecutor = writeExecutor; _imageCacheStatsTracker = imageCacheStatsTracker; _stagingArea = StagingArea.Instance; _writeToDiskCacheTasks = new ConcurrentDictionary <ICacheKey, Task>(); }
/// <summary> /// Returns the instrumented <see cref="EncodedCountingMemoryCacheFactory"/>. /// </summary> public static IMemoryCache <ICacheKey, IPooledByteBuffer> Get( CountingMemoryCache <ICacheKey, IPooledByteBuffer> encodedCountingMemoryCache, IImageCacheStatsTracker imageCacheStatsTracker) { imageCacheStatsTracker.RegisterEncodedMemoryCache(encodedCountingMemoryCache); IMemoryCacheTracker memoryCacheTracker = new MemoryCacheTrackerImpl( () => { imageCacheStatsTracker.OnMemoryCacheHit(); }, () => { imageCacheStatsTracker.OnMemoryCacheMiss(); }, () => { imageCacheStatsTracker.OnMemoryCachePut(); }); return(new InstrumentedMemoryCache <ICacheKey, IPooledByteBuffer>( encodedCountingMemoryCache, memoryCacheTracker)); }
/// <summary> /// Gets the instrumented memory cache. /// </summary> public static IMemoryCache <ICacheKey, CloseableImage> Get( CountingMemoryCache <ICacheKey, CloseableImage> bitmapCountingMemoryCache, IImageCacheStatsTracker imageCacheStatsTracker) { imageCacheStatsTracker.RegisterBitmapMemoryCache(bitmapCountingMemoryCache); IMemoryCacheTracker memoryCacheTracker = new MemoryCacheTrackerImpl( () => { imageCacheStatsTracker.OnBitmapCacheHit(); }, () => { imageCacheStatsTracker.OnBitmapCacheMiss(); }, () => { imageCacheStatsTracker.OnBitmapCachePut(); }); return(new InstrumentedMemoryCache <ICacheKey, CloseableImage>( bitmapCountingMemoryCache, memoryCacheTracker)); }
/// <summary> /// Sets the image cache stats tracker. /// </summary> public Builder SetImageCacheStatsTracker(IImageCacheStatsTracker imageCacheStatsTracker) { ImageCacheStatsTracker = imageCacheStatsTracker; return(this); }