示例#1
0
        public async Task <Image> GetImageAsync(ImageCacheKey cacheKey)
        {
            if (cacheKey == null)
            {
                throw new ArgumentNullException(nameof(cacheKey));
            }

            byte[] imageBytes;
            return((imageBytes = await _distributedCache.GetAsync(cacheKey.ToString())) == null
                ? null
                : Image.FromBytes(imageBytes));
        }
示例#2
0
        public async Task CacheImageAsync(ImageCacheKey cacheKey, Image image)
        {
            if (cacheKey == null)
            {
                throw new ArgumentNullException(nameof(cacheKey));
            }
            if (image == null)
            {
                throw new ArgumentNullException(nameof(image));
            }

            await _distributedCache.SetAsync(
                cacheKey.ToString(),
                image.ToBytes(),
                new DistributedCacheEntryOptions());
        }