At Aerion we use the awesome ImageProcessor library (A .NET library for on-the-fly processing of images) when we need to have image caching and the ability to request images at different sizes based on designs. As with most things when moving the code to an AzureAzure is a cloud platform by Microsoft that provides you with many different services that you can consume on a... App Service we try to utilise the Slot Settings so that we can have different configurations for the various slots that we use.
This posed a slight problem with the ImageProcessor library and the AzureAzure is a cloud platform by Microsoft that provides you with many different services that you can consume on a... cacheThe term cache can be used in a few different ways in software development. However, the most common is that... plug-in, as there didn’t seem to be a documented way to dynamically configure the plugin and change Storage connection strings without recompilation. We started digging through the issues within the GitHub project and found a proposed solution that had been merged into the code base. https://github.com/JimBobSquarePants/ImageProcessor/issues/432
To allow dynamic configuration based on Slot Settings we need to extend the existing AzureAzure is a cloud platform by Microsoft that provides you with many different services that you can consume on a... CacheThe term cache can be used in a few different ways in software development. However, the most common is that... module
namespace #######.ImageProcessServices { public class AzureBlobCacheFromAppSettings : AzureBlobCache { public AzureBlobCacheFromAppSettings(string requestPath, string fullPath, string querystring) : base(requestPath, fullPath, querystring) { } protected override void AugmentSettings(Dictionary<string, string> settings) { settings["CachedStorageAccount"] = ConfigurationManager.AppSettings["CachedStorageAccount"]?.ToString(); settings["CachedBlobContainer"] = ConfigurationManager.AppSettings["CachedBlobContainer"]?.ToString(); } } }
The key part to the above code is the AugmentSettings override. The base constructor for ImageCacheBase calls AugmentSettingsCore which in turn call AugmentSettings. This allows us an entry point to modify the settings for the plugin before the rest of it is initialised. By setting the storageAccount and Container, we allow the plugin to use the connection string provided by the app settings and also specify the cacheThe term cache can be used in a few different ways in software development. However, the most common is that... folder.
Now you are able to use a different storage account or different cacheThe term cache can be used in a few different ways in software development. However, the most common is that... folder based on the different slots you have set up.
The above code example could be improved with some error handling or by providing default values if the keys are not present.