public AzureOutputCacheStorageProvider(ShellSettings shellSettings, IAzureOutputCacheHolder cacheHolder) { var region = shellSettings.Name; // Azure Cache supports only alphanumeric strings for regions, but Orchard supports some // non-alphanumeric characters in tenant names. Remove all non-alphanumering characters // from the region, and append the hash code of the original string to mitigate the risk // of two distinct original region strings yielding the same transformed region string. _regionAlphaNumeric = new String(Array.FindAll(region.ToCharArray(), Char.IsLetterOrDigit)) + region.GetHashCode().ToString(CultureInfo.InvariantCulture); _cache = cacheHolder.TryGetDataCache(() => { CacheClientConfiguration cacheConfig; try { cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix); cacheConfig.Validate(); } catch (Exception ex) { throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.OutputCacheFeatureName), ex); } var cache = cacheConfig.CreateCache(); cache.CreateRegion(_regionAlphaNumeric); return(cache); }); }
public AzureOutputCacheStorageProvider(ShellSettings shellSettings, IAzureOutputCacheHolder cacheHolder) { var region = shellSettings.Name; // Azure Cache supports only alphanumeric strings for regions, but Orchard supports some // non-alphanumeric characters in tenant names. Remove all non-alphanumering characters // from the region, and append the hash code of the original string to mitigate the risk // of two distinct original region strings yielding the same transformed region string. _regionAlphaNumeric = new String(Array.FindAll(region.ToCharArray(), Char.IsLetterOrDigit)) + region.GetHashCode().ToString(CultureInfo.InvariantCulture); _cache = cacheHolder.TryGetDataCache(() => { CacheClientConfiguration cacheConfig; try { cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix); cacheConfig.Validate(); } catch (Exception ex) { throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.OutputCacheFeatureName), ex); } var cache = cacheConfig.CreateCache(); cache.CreateRegion(_regionAlphaNumeric); return cache; }); }