Example #1
0
        public ProductImage TryGetImage(ProductImage image)
        {
            var code = image.GetHashCode();

            if (!Cache.TryGetValue(code, out ProductImage cachedImage))
            {
                Logger.LogInformation($"Image not Cached - Caching image - Name:{image.Name} Height:{image.Height} Width:{image.Width} Format:{image.Format.ToString()} with Watermark:'{image.Watermark}' Code:{code}");
                image.ProcessImage();
                cachedImage = image;
                var cacheDuration     = double.Parse(Configuration.GetSection("CacheSettings:Duration").Value);
                var cacheEntryOptions = new MemoryCacheEntryOptions()
                                        .SetSize(1)
                                        .SetSlidingExpiration(TimeSpan.FromSeconds(cacheDuration));
                Cache.Set(code, cachedImage, cacheEntryOptions);
            }
            else
            {
                Logger.LogInformation($"Returning Cached image - Name:{image.Name} Height:{image.Height} Width:{image.Width} Format:{image.Format.ToString()} with Watermark:'{image.Watermark}' Code:{code}");
            }
            return(cachedImage);
        }