• Articles
  • API Documentation
Search Results for

    Show / Hide Table of Contents
    • ImageSharp
      • Getting Started
        • Pixel Formats
        • Image Formats
        • Processing Images
          • Resizing Images
          • Create an animated GIF
        • Working with Pixel Buffers
        • Configuration
        • Memory Management
        • Security Considerations
    • ImageSharp.Drawing
      • Getting Started
    • ImageSharp.Web
      • Getting Started
        • Processing Commands
        • Image Providers
        • Image Caches
    • Fonts
      • Getting Started
      • Custom Rendering

    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, by default, 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

    • Package Manager
    • .NET CLI
    • PackageReference
    • Paket CLI
    PM > Install-Package SixLabors.ImageSharp.Web.Providers.Azure -Version VERSION_NUMBER
    
    dotnet add package SixLabors.ImageSharp.Web.Providers.Azure --version VERSION_NUMBER
    
    <PackageReference Include="SixLabors.ImageSharp.Web.Providers.Azure" Version="VERSION_NUMBER" />
    
    paket add 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 use a cache folder under the container.
        options.CacheFolder = {AZURE_CACHE_FOLDER};
        
        // 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.

    AWSS3StorageCache

    This cache allows the caching of image files using Amazon Simple Storage Service (Amazon S3) and is available as an external package installable via NuGet

    • Package Manager
    • .NET CLI
    • PackageReference
    • Paket CLI
    PM > Install-Package SixLabors.ImageSharp.Web.Providers.AWS -Version VERSION_NUMBER
    
    dotnet add package SixLabors.ImageSharp.Web.Providers.AWS --version VERSION_NUMBER
    
    <PackageReference Include="SixLabors.ImageSharp.Web.Providers.AWS" Version="VERSION_NUMBER" />
    
    paket add SixLabors.ImageSharp.Web.Providers.AWS --version VERSION_NUMBER
    

    Once installed the cache AWSS3StorageCacheOptions can be configured as follows:

    // Configure and register the bucket.  
    // Alteratively use `appsettings.json` to represent the class and bind those settings.
    .Configure<AWSS3StorageCacheOptions>(options =>
    {
        options.Endpoint = {AWS_ENDPOINT};
        options.BucketName = {AWS_BUCKET_NAME};
        options.AccessKey = {AWS_ACCESS_KEY};
        options.AccessSecret = {AWS_ACCESS_SECRET};
        options.Region = {AWS_REGION};
    
        // Optionally use a cache folder under the bucket.
        options.CacheFolder = {AWS_CACHE_FOLDER};
        
        // Optionally create the cache bucket on startup if not already created.
        AWSS3StorageCache.CreateIfNotExists(options, S3CannedACL.Private);
    })
    .SetCache<AWSS3StorageCache>()
    

    Images are cached using a hash of the request URL as the object name. All appropriate metadata is stored in the object properties to correctly serve the object with the correct response headers.

    • Edit this page
    In this article
    Back to top Generated by DocFX