public IActionResult Get(string file, int width, int height, string backgroundColour = null,
                                 string watermark = null, string fileType = "png")
        {
            try
            {
                var criteriaBuilder = ImageCriteria.NewBuilder()
                                      .SetSize(width, height)
                                      .SetImageFormat(ParseFormat(fileType));

                if (backgroundColour != null)
                {
                    criteriaBuilder.SetBackgroundColour(backgroundColour);
                }

                if (watermark != null)
                {
                    criteriaBuilder.SetWatermark(watermark);
                }

                var criteria = criteriaBuilder.Build(file);

                var imageBytes = _imageFetcher.Fetch(criteria);

                return(File(imageBytes, criteria.Format.MimeType()));
            } catch (ArgumentException ex)
            {
                return(BadRequest(new { errorMessage = ex.Message }));
            } catch (Exception ex)
            {
                _logger.LogError("Failed to fetch image " + ex.Message);
                return(StatusCode(500));
            }
        }
        public byte[] Fetch(ImageCriteria criteria)
        {
            var value = _cache.Get <byte[]>(criteria.ToHash());

            if (value == null)
            {
                var image = _source.Fetch(criteria);
                _cache.Set(criteria.ToHash(), image, new MemoryCacheEntryOptions()
                {
                    Size = image.Length
                });

                return(image);
            }

            return(value);
        }