Ejemplo n.º 1
0
        private ImageCacheEntry SetImageToCacheInternal(string key, ImageCacheEntry imageCacheEntry, byte[] imageAsBytes, ImageCacheOptions opts)
        {
            var entryOptions = new MemoryCacheEntryOptions();

            entryOptions.RegisterPostEvictionCallback(_callback);
            entryOptions.SetSlidingExpiration(TimeSpan.FromMilliseconds(opts.ExpirationTimeSpanInMilliseconds));

            imageCacheEntry.FullPath = opts.PathToCacheDirectory;

            var entered = _memoryCache.Set <ImageCacheEntry>(key, imageCacheEntry, entryOptions);

            return(this.SaveImageToFolder(entered, imageAsBytes) ? entered : null);
        }
 public static IApplicationBuilder UseImagesCaching(
     this IApplicationBuilder builder, ImageCacheOptions opts)
 {
     return(builder.UseMiddleware <ImagesCacheMiddleware>(opts));
 }
Ejemplo n.º 3
0
        public ImageCacheEntry SetImageToCache(string key, ImageCacheEntry imageCacheEntry, byte[] imageAsBytes, ImageCacheOptions opts)
        {
            if (imageCacheEntry is null)
            {
                throw new ArgumentNullException(nameof(imageCacheEntry));
            }

            if (key is null)
            {
                throw new ArgumentNullException(nameof(key));
            }

            return(((MemoryCache)_memoryCache).Count == opts.MaxCountOfCachedImages ? null : this.SetImageToCacheInternal(key, imageCacheEntry, imageAsBytes, opts));
        }
Ejemplo n.º 4
0
 public ImagesCacheMiddleware(RequestDelegate next, ImageCacheOptions opts)
 {
     _next = next;
     _opts = opts;
 }