Azure Blob CacheControl

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.
8 anos atrás
Hi,

When using Azure Blob Storage you should set the header Cache Control to prevent the clients from fetching the picture every time they come to your site. An easy way of doing this is by adding this code last in AzurePictureService.cs in SaveThumb:


blockBlob.FetchAttributes();
var cacheControl = "max-age=2592000, must-revalidate";
blockBlob.Properties.CacheControl = cacheControl;
blockBlob.SetProperties();


You could also add the following code to set the content type:


var fileExtension = Path.GetExtension(thumbFileName);
var contentType = "application/octet-stream";
switch (fileExtension)
{
      case ".jpg": contentType = "image/jpeg"; break;
      case ".jpeg": contentType = "image/jpeg"; break;
      case ".png": contentType = "image/png"; break;
      case ".gif": contentType = "image/gif"; break;
}
blockBlob.Properties.ContentType = contentType;
8 anos atrás
Ty, I asked abt this but couldn't get an answer on forum before. Nopcommerce needs to have better Azure support. Did you find a solution for static contents? Still looking for that answer as well...
8 anos atrás
I was using cloudberry to set the headers :)
8 anos atrás
dianoche wrote:
Ty, I asked abt this but couldn't get an answer on forum before. Nopcommerce needs to have better Azure support. Did you find a solution for static contents? Still looking for that answer as well...


Hi,

Sorry but I didn't see your question in the forum before. I guess I had my head too deep in my code to see the questions...

Haven't checked static content... Guess it is a little more involved to solve that one...

Hope this was helpful to you!

Greetings
/Johan
8 anos atrás
Hi Johan,

Thanks a lot for suggestion. I've just created a work item
7 anos atrás
And done. You can see the changes in this commit.
Thanks for the suggestion.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.