@@ -17,6 +17,7 @@ public class AWSS3StorageCache : IImageCache
17
17
{
18
18
private readonly IAmazonS3 amazonS3Client ;
19
19
private readonly string bucketName ;
20
+ private readonly string cacheFolder ;
20
21
21
22
/// <summary>
22
23
/// Initializes a new instance of the <see cref="AWSS3StorageCache"/> class.
@@ -28,17 +29,21 @@ public AWSS3StorageCache(IOptions<AWSS3StorageCacheOptions> cacheOptions)
28
29
AWSS3StorageCacheOptions options = cacheOptions . Value ;
29
30
this . bucketName = options . BucketName ;
30
31
this . amazonS3Client = AmazonS3ClientFactory . CreateClient ( options ) ;
32
+ this . cacheFolder = string . IsNullOrEmpty ( options . CacheFolder )
33
+ ? string . Empty
34
+ : options . CacheFolder . Trim ( ) . Trim ( '/' ) + '/' ;
31
35
}
32
36
33
37
/// <inheritdoc/>
34
38
public async Task < IImageCacheResolver ? > GetAsync ( string key )
35
39
{
36
- GetObjectMetadataRequest request = new ( ) { BucketName = this . bucketName , Key = key } ;
40
+ string keyWithFolder = this . GetKeyWithFolder ( key ) ;
41
+ GetObjectMetadataRequest request = new ( ) { BucketName = this . bucketName , Key = keyWithFolder } ;
37
42
try
38
43
{
39
44
// HEAD request throws a 404 if not found.
40
45
MetadataCollection metadata = ( await this . amazonS3Client . GetObjectMetadataAsync ( request ) ) . Metadata ;
41
- return new AWSS3StorageCacheResolver ( this . amazonS3Client , this . bucketName , key , metadata ) ;
46
+ return new AWSS3StorageCacheResolver ( this . amazonS3Client , this . bucketName , keyWithFolder , metadata ) ;
42
47
}
43
48
catch
44
49
{
@@ -52,7 +57,7 @@ public Task SetAsync(string key, Stream stream, ImageCacheMetadata metadata)
52
57
PutObjectRequest request = new ( )
53
58
{
54
59
BucketName = this . bucketName ,
55
- Key = key ,
60
+ Key = this . GetKeyWithFolder ( key ) ,
56
61
ContentType = metadata . ContentType ,
57
62
InputStream = stream ,
58
63
AutoCloseStream = false
@@ -118,6 +123,9 @@ public Task SetAsync(string key, Stream stream, ImageCacheMetadata metadata)
118
123
return null ;
119
124
}
120
125
126
+ private string GetKeyWithFolder ( string key )
127
+ => this . cacheFolder + key ;
128
+
121
129
/// <summary>
122
130
/// <see href="https://github.com/aspnet/AspNetIdentity/blob/b7826741279450c58b230ece98bd04b4815beabf/src/Microsoft.AspNet.Identity.Core/AsyncHelper.cs"/>
123
131
/// </summary>
0 commit comments