Image Caches
ImageSharp.Web caches the result of any valid processing operation to allow the fast retrieval of future identical requests. The cache is smart, storing additional metadata to allow the detection of updated source images and can be configured to a fine degree to determine the duration a processed image should be cached for.
Note
It is possible to configure your own image cache by implementing and registering your own version of the IImageCache interface.
The following caches are available for the middleware.
PhysicalFileSystemCache
The PhysicalFileSystemCache stores processed image files in the web root folder. This is the default cache installed when configuring the middleware.
Images are cached in separate folders based upon a hash of the request URL. this allows the caching of millions of image files without slowing down the file system.
AzureBlobStorageImageCache
This cache allows the caching of image files using Azure Blob Storage and is available as an external package installable via NuGet
PM > Install-Package SixLabors.ImageSharp.Web.Providers.Azure -Version VERSION_NUMBER
Once installed the cache AzureBlobStorageCacheOptions can be configured as follows:
// Configure and register the container.
// Alteratively use `appsettings.json` to represent the class and bind those settings.
.Configure<AzureBlobStorageCacheOptions>(options =>
{
options.ConnectionString = {AZURE_CONNECTION_STRING};
options.ContainerName = {AZURE_CONTAINER_NAME};
// Optionally create the cache container on startup if not already created.
AzureBlobStorageCache.CreateIfNotExists(options, PublicAccessType.None);
})
.SetCache<AzureBlobStorageCache>()
Images are cached using a hash of the request URL as the blob name. All appropriate metadata is stored in the blob properties to correctly serve the blob with the correct response headers.