mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Removing static fields usage
This commit is contained in:
parent
bde2006dc7
commit
a567a99cd4
@ -1,21 +1,20 @@
|
||||
using Microsoft.ApplicationServer.Caching;
|
||||
using Orchard.Azure.Services.Environment.Configuration;
|
||||
using Orchard.Environment.Configuration;
|
||||
using System;
|
||||
|
||||
namespace Orchard.Azure.Services.Caching {
|
||||
|
||||
public class CacheClientConfiguration {
|
||||
|
||||
public static CacheClientConfiguration FromPlatformConfiguration(ShellSettings shellSettings, string settingNamePrefix) {
|
||||
var portString = PlatformConfiguration.GetSetting(Constants.CachePortSettingName, shellSettings, settingNamePrefix);
|
||||
var isSharedCachingString = PlatformConfiguration.GetSetting(Constants.CacheIsSharedCachingSettingName, shellSettings, settingNamePrefix);
|
||||
public static CacheClientConfiguration FromPlatformConfiguration(string tenant, string settingNamePrefix) {
|
||||
var portString = PlatformConfiguration.GetSetting(Constants.CachePortSettingName, tenant, settingNamePrefix);
|
||||
var isSharedCachingString = PlatformConfiguration.GetSetting(Constants.CacheIsSharedCachingSettingName, tenant, settingNamePrefix);
|
||||
return new CacheClientConfiguration {
|
||||
HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, shellSettings, settingNamePrefix),
|
||||
CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, shellSettings, settingNamePrefix),
|
||||
Hostname = PlatformConfiguration.GetSetting(Constants.CacheHostnameSettingName, shellSettings, settingNamePrefix),
|
||||
HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, tenant, settingNamePrefix),
|
||||
CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, tenant, settingNamePrefix),
|
||||
Hostname = PlatformConfiguration.GetSetting(Constants.CacheHostnameSettingName, tenant, settingNamePrefix),
|
||||
Port = String.IsNullOrWhiteSpace(portString) ? 0 : Int32.Parse(portString),
|
||||
AuthorizationToken = PlatformConfiguration.GetSetting(Constants.CacheAuthorizationTokenSettingName, shellSettings, settingNamePrefix),
|
||||
AuthorizationToken = PlatformConfiguration.GetSetting(Constants.CacheAuthorizationTokenSettingName, tenant, settingNamePrefix),
|
||||
IsSharedCaching = !String.IsNullOrWhiteSpace(isSharedCachingString) && Boolean.Parse(isSharedCachingString)
|
||||
};
|
||||
}
|
||||
|
@ -11,18 +11,7 @@ namespace Orchard.Azure.Services.Caching.Database {
|
||||
[OrchardSuppressDependency("Orchard.Data.DefaultDatabaseCacheConfiguration")]
|
||||
public class AzureCacheConfiguration : Component, IDatabaseCacheConfiguration {
|
||||
|
||||
public static CacheClientConfiguration CacheClientConfiguration;
|
||||
|
||||
public AzureCacheConfiguration(ShellSettings shellSettings) {
|
||||
|
||||
try {
|
||||
CacheClientConfiguration = CacheClientConfiguration.FromPlatformConfiguration(shellSettings, Constants.DatabaseCacheSettingNamePrefix);
|
||||
CacheClientConfiguration.Validate();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.DatabaseCacheFeatureName), ex);
|
||||
}
|
||||
|
||||
_shellSettings = shellSettings;
|
||||
}
|
||||
|
||||
|
@ -1,45 +1,26 @@
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using NHibernate.Cache;
|
||||
using System;
|
||||
using Microsoft.ApplicationServer.Caching;
|
||||
using NHibernate;
|
||||
|
||||
namespace Orchard.Azure.Services.Caching.Database {
|
||||
|
||||
public class AzureCacheProvider : ICacheProvider {
|
||||
|
||||
private static readonly IDictionary<string, DataCache> _cacheDictionary = new ConcurrentDictionary<string, DataCache>();
|
||||
|
||||
private static DataCache GetCache(IInternalLogger logger, CacheClientConfiguration config) {
|
||||
string key = config.ToString();
|
||||
if (!_cacheDictionary.ContainsKey(key)) {
|
||||
logger.DebugFormat("Creating new DataCache with key '{0}'.", key);
|
||||
_cacheDictionary[key] = AzureCacheConfiguration.CacheClientConfiguration.CreateCache();
|
||||
}
|
||||
else {
|
||||
logger.DebugFormat("Reusing existing DataCache with key '{0}'.", key);
|
||||
}
|
||||
|
||||
return _cacheDictionary[key];
|
||||
}
|
||||
|
||||
public AzureCacheProvider() {
|
||||
_logger = LoggerProvider.LoggerFor(typeof(AzureCacheProvider));
|
||||
}
|
||||
|
||||
private readonly IInternalLogger _logger;
|
||||
|
||||
#region ICacheProvider Members
|
||||
|
||||
public ICache BuildCache(string regionName, IDictionary<string, string> properties) {
|
||||
CacheClientConfiguration configuration;
|
||||
|
||||
try {
|
||||
configuration = CacheClientConfiguration.FromPlatformConfiguration(regionName, Constants.DatabaseCacheSettingNamePrefix);
|
||||
configuration.Validate();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.DatabaseCacheFeatureName), ex);
|
||||
}
|
||||
|
||||
string enableCompressionString;
|
||||
properties.TryGetValue("compression_enabled", out enableCompressionString);
|
||||
|
||||
// Using static fields to communicate host identifier and cache name from AzureCacheConfiguration to
|
||||
// this class might cause problems in multi-tenancy scenarios when tenants have different settings
|
||||
// for these in platform configuration. We should think of something more robust.
|
||||
var cache = GetCache(_logger, AzureCacheConfiguration.CacheClientConfiguration);
|
||||
var cache = configuration.CreateCache();
|
||||
|
||||
TimeSpan? expiration = null;
|
||||
string expirationString;
|
||||
@ -47,7 +28,7 @@ namespace Orchard.Azure.Services.Caching.Database {
|
||||
expiration = TimeSpan.FromSeconds(Int32.Parse(expirationString));
|
||||
}
|
||||
|
||||
return new AzureCacheClient(cache, AzureCacheConfiguration.CacheClientConfiguration.IsSharedCaching, regionName, expiration);
|
||||
return new AzureCacheClient(cache, configuration.IsSharedCaching, regionName, expiration);
|
||||
}
|
||||
|
||||
public long NextTimestamp() {
|
||||
@ -59,7 +40,5 @@ namespace Orchard.Azure.Services.Caching.Database {
|
||||
|
||||
public void Stop() {
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
@ -17,7 +17,7 @@ namespace Orchard.Azure.Services.Caching.Output {
|
||||
public AzureOutputCacheStorageProvider(ShellSettings shellSettings) {
|
||||
|
||||
try {
|
||||
_cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings, Constants.OutputCacheSettingNamePrefix);
|
||||
_cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix);
|
||||
_cacheConfig.Validate();
|
||||
}
|
||||
catch (Exception ex) {
|
||||
|
@ -1,6 +1,4 @@
|
||||
using Microsoft.WindowsAzure;
|
||||
using Orchard.Environment.Configuration;
|
||||
using System;
|
||||
|
||||
namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
|
||||
@ -11,11 +9,11 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
||||
/// secondly with no prefix.
|
||||
/// </summary>
|
||||
/// <param name="name">The name of the setting to read.</param>
|
||||
/// <param name="shellSettings">The ShellSettings object for the current tenant.</param>
|
||||
/// <param name="tenant">The curren tenant's name.</param>
|
||||
/// <param name="namePrefix">An optional prefix to prepend the setting name with.</param>
|
||||
/// <returns>The value of the setting if found with or without tenant name prefix, otherwise null.</returns>
|
||||
public static string GetSetting(string name, ShellSettings shellSettings, string namePrefix = null) {
|
||||
var tenantName = shellSettings.Name + ":" + namePrefix + name;
|
||||
public static string GetSetting(string name, string tenant, string namePrefix = null) {
|
||||
var tenantName = tenant + ":" + namePrefix + name;
|
||||
var fallbackName = namePrefix + name;
|
||||
return CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ namespace Orchard.Azure.Services.FileSystems.Media {
|
||||
public class AzureBlobStorageProvider : AzureFileSystem, IStorageProvider {
|
||||
|
||||
public AzureBlobStorageProvider(ShellSettings shellSettings, IMimeTypeProvider mimeTypeProvider)
|
||||
: this(PlatformConfiguration.GetSetting(Constants.MediaStorageStorageConnectionStringSettingName, shellSettings), Constants.MediaStorageContainerName, shellSettings.Name, mimeTypeProvider) {
|
||||
: this(PlatformConfiguration.GetSetting(Constants.MediaStorageStorageConnectionStringSettingName, shellSettings.Name), Constants.MediaStorageContainerName, shellSettings.Name, mimeTypeProvider) {
|
||||
}
|
||||
|
||||
public AzureBlobStorageProvider(string storageConnectionString, string containerName, string rootFolderPath, IMimeTypeProvider mimeTypeProvider)
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using Orchard.OutputCache.Models;
|
||||
using Orchard;
|
||||
|
||||
namespace Orchard.OutputCache.Services {
|
||||
public interface IOutputCacheStorageProvider : IDependency {
|
||||
|
Loading…
Reference in New Issue
Block a user