@@ -16,6 +16,7 @@ namespace SixLabors.ImageSharp.Web.Caching.Azure;
1616public class AzureBlobStorageCache : IImageCache
1717{
1818 private readonly BlobContainerClient container ;
19+ private readonly string cacheFolder ;
1920
2021 /// <summary>
2122 /// Initializes a new instance of the <see cref="AzureBlobStorageCache"/> class.
@@ -27,12 +28,15 @@ public AzureBlobStorageCache(IOptions<AzureBlobStorageCacheOptions> cacheOptions
2728 AzureBlobStorageCacheOptions options = cacheOptions . Value ;
2829
2930 this . container = new BlobContainerClient ( options . ConnectionString , options . ContainerName ) ;
31+ this . cacheFolder = string . IsNullOrEmpty ( options . CacheFolder )
32+ ? string . Empty
33+ : options . CacheFolder . Trim ( ) . Trim ( '/' ) + '/' ;
3034 }
3135
3236 /// <inheritdoc/>
3337 public async Task < IImageCacheResolver ? > GetAsync ( string key )
3438 {
35- BlobClient blob = this . container . GetBlobClient ( key ) ;
39+ BlobClient blob = this . container . GetBlobClient ( this . GetBlobName ( key ) ) ;
3640
3741 if ( ! await blob . ExistsAsync ( ) )
3842 {
@@ -45,7 +49,7 @@ public AzureBlobStorageCache(IOptions<AzureBlobStorageCacheOptions> cacheOptions
4549 /// <inheritdoc/>
4650 public Task SetAsync ( string key , Stream stream , ImageCacheMetadata metadata )
4751 {
48- BlobClient blob = this . container . GetBlobClient ( key ) ;
52+ BlobClient blob = this . container . GetBlobClient ( this . GetBlobName ( key ) ) ;
4953
5054 BlobHttpHeaders headers = new ( )
5155 {
@@ -79,4 +83,7 @@ public static Response<BlobContainerInfo> CreateIfNotExists(
7983 AzureBlobStorageCacheOptions options ,
8084 PublicAccessType accessType )
8185 => new BlobContainerClient ( options . ConnectionString , options . ContainerName ) . CreateIfNotExists ( accessType ) ;
86+
87+ private string GetBlobName ( string key )
88+ => this . cacheFolder + key ;
8289}
0 commit comments