/// <summary>
        /// Returns the encoded <see cref="CountingMemoryCache{K, V}"/>.
        /// </summary>
        public static CountingMemoryCache <ICacheKey, IPooledByteBuffer> Get(
            ISupplier <MemoryCacheParams> encodedMemoryCacheParamsSupplier,
            IMemoryTrimmableRegistry memoryTrimmableRegistry,
            PlatformBitmapFactory platformBitmapFactory)
        {
            IValueDescriptor <IPooledByteBuffer> valueDescriptor =
                new ValueDescriptorImpl <IPooledByteBuffer>(
                    (value) =>
            {
                return(value.Size);
            });

            ICacheTrimStrategy trimStrategy = new NativeMemoryCacheTrimStrategy();

            CountingMemoryCache <ICacheKey, IPooledByteBuffer> countingCache =
                new CountingMemoryCache <ICacheKey, IPooledByteBuffer>(
                    valueDescriptor,
                    trimStrategy,
                    encodedMemoryCacheParamsSupplier,
                    platformBitmapFactory,
                    false);

            memoryTrimmableRegistry.RegisterMemoryTrimmable(countingCache);

            return(countingCache);
        }
Example #2
0
        /// <summary>
        /// Instantiates the bitmap counting memory cache.
        /// </summary>
        public static CountingMemoryCache <ICacheKey, CloseableImage> Get(
            ISupplier <MemoryCacheParams> bitmapMemoryCacheParamsSupplier,
            IMemoryTrimmableRegistry memoryTrimmableRegistry,
            PlatformBitmapFactory platformBitmapFactory,
            bool isExternalCreatedBitmapLogEnabled)
        {
            IValueDescriptor <CloseableImage> valueDescriptor =
                new ValueDescriptorImpl <CloseableImage>(
                    (value) =>
            {
                return(value.SizeInBytes);
            });

            ICacheTrimStrategy trimStrategy = new BitmapMemoryCacheTrimStrategy();

            CountingMemoryCache <ICacheKey, CloseableImage> countingCache =
                new CountingMemoryCache <ICacheKey, CloseableImage>(
                    valueDescriptor,
                    trimStrategy,
                    bitmapMemoryCacheParamsSupplier,
                    platformBitmapFactory,
                    isExternalCreatedBitmapLogEnabled);

            memoryTrimmableRegistry.RegisterMemoryTrimmable(countingCache);

            return(countingCache);
        }
Example #3
0
        /// <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));
        }