Example #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PhysicalFileSystemCache"/> class.
        /// </summary>
        /// <param name="cacheOptions">The cache configuraiton options.</param>
        /// <param name="environment">The hosting environment the application is running in.</param>
        /// <param name="options">The middleware configuration options.</param>
        /// <param name="formatUtilities">Contains various format helper methods based on the current configuration.</param>
        public PhysicalFileSystemCache(
            IOptions <PhysicalFileSystemCacheOptions> cacheOptions,
            IWebHostEnvironment environment,
            IOptions <ImageSharpMiddlewareOptions> options,
            FormatUtilities formatUtilities)
        {
            Guard.NotNull(environment, nameof(environment));
            Guard.NotNull(options, nameof(options));

            Guard.NotNullOrWhiteSpace(
                environment.WebRootPath,
                nameof(environment.WebRootPath),
                "The folder 'wwwroot' that contains the web-servable application content files is missing. Please add this folder to the application root to allow caching.");

            this.cacheOptions  = cacheOptions != null ? cacheOptions.Value : new PhysicalFileSystemCacheOptions();
            this.cacheRootPath = Path.Combine(environment.WebRootPath, this.cacheOptions.CacheFolder);
            if (!Directory.Exists(this.cacheRootPath))
            {
                Directory.CreateDirectory(this.cacheRootPath);
            }

            this.fileProvider  = new PhysicalFileProvider(this.cacheRootPath);
            this.options       = options.Value;
            this.formatUtilies = formatUtilities;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PhysicalFileSystemCache"/> class.
        /// </summary>
        /// <param name="cacheOptions">The cache configuraiton options.</param>
        /// <param name="environment">The hosting environment the application is running in.</param>
        /// <param name="options">The middleware configuration options.</param>
        /// <param name="formatUtilities">Contains various format helper methods based on the current configuration.</param>
        public PhysicalFileSystemCache(
            IOptions <PhysicalFileSystemCacheOptions> cacheOptions,
            IHostingEnvironment environment,
            IOptions <ImageSharpMiddlewareOptions> options,
            FormatUtilities formatUtilities)
        {
            Guard.NotNull(environment, nameof(environment));
            Guard.NotNull(options, nameof(options));

            Guard.NotNullOrWhiteSpace(
                environment.WebRootPath,
                nameof(environment.WebRootPath),
                "The folder 'wwwroot' that contains the web-servable application content files is missing. Please add this folder to the application root to allow caching.");

            this.environment   = environment;
            this.fileProvider  = this.environment.WebRootFileProvider;
            this.cacheOptions  = cacheOptions != null ? cacheOptions.Value : new PhysicalFileSystemCacheOptions();
            this.options       = options.Value;
            this.formatUtilies = formatUtilities;
        }