mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Ignoring tenant specific configuration for db cache
There is no way to configure the cache provider for specific tenants, thus ignoring it. NHibernate should take an instance instead of a type for the provider.
This commit is contained in:
@@ -6,15 +6,15 @@ namespace Orchard.Azure.Services.Caching {
|
|||||||
|
|
||||||
public class CacheClientConfiguration {
|
public class CacheClientConfiguration {
|
||||||
|
|
||||||
public static CacheClientConfiguration FromPlatformConfiguration(string tenant, string settingNamePrefix) {
|
public static CacheClientConfiguration FromPlatformConfiguration(string settingNamePrefix) {
|
||||||
var portString = PlatformConfiguration.GetSetting(Constants.CachePortSettingName, tenant, settingNamePrefix);
|
var portString = PlatformConfiguration.GetSetting(Constants.CachePortSettingName, settingNamePrefix);
|
||||||
var isSharedCachingString = PlatformConfiguration.GetSetting(Constants.CacheIsSharedCachingSettingName, tenant, settingNamePrefix);
|
var isSharedCachingString = PlatformConfiguration.GetSetting(Constants.CacheIsSharedCachingSettingName, settingNamePrefix);
|
||||||
return new CacheClientConfiguration {
|
return new CacheClientConfiguration {
|
||||||
HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, tenant, settingNamePrefix),
|
HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, settingNamePrefix),
|
||||||
CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, tenant, settingNamePrefix),
|
CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, settingNamePrefix),
|
||||||
Hostname = PlatformConfiguration.GetSetting(Constants.CacheHostnameSettingName, tenant, settingNamePrefix),
|
Hostname = PlatformConfiguration.GetSetting(Constants.CacheHostnameSettingName, settingNamePrefix),
|
||||||
Port = String.IsNullOrWhiteSpace(portString) ? 0 : Int32.Parse(portString),
|
Port = String.IsNullOrWhiteSpace(portString) ? 0 : Int32.Parse(portString),
|
||||||
AuthorizationToken = PlatformConfiguration.GetSetting(Constants.CacheAuthorizationTokenSettingName, tenant, settingNamePrefix),
|
AuthorizationToken = PlatformConfiguration.GetSetting(Constants.CacheAuthorizationTokenSettingName, settingNamePrefix),
|
||||||
IsSharedCaching = !String.IsNullOrWhiteSpace(isSharedCachingString) && Boolean.Parse(isSharedCachingString)
|
IsSharedCaching = !String.IsNullOrWhiteSpace(isSharedCachingString) && Boolean.Parse(isSharedCachingString)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@@ -10,7 +10,7 @@ namespace Orchard.Azure.Services.Caching.Database {
|
|||||||
CacheClientConfiguration configuration;
|
CacheClientConfiguration configuration;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
configuration = CacheClientConfiguration.FromPlatformConfiguration(regionName, Constants.DatabaseCacheSettingNamePrefix);
|
configuration = CacheClientConfiguration.FromPlatformConfiguration(Constants.DatabaseCacheSettingNamePrefix);
|
||||||
configuration.Validate();
|
configuration.Validate();
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
|
@@ -17,7 +17,7 @@ namespace Orchard.Azure.Services.Caching.Output {
|
|||||||
public AzureOutputCacheStorageProvider(ShellSettings shellSettings) {
|
public AzureOutputCacheStorageProvider(ShellSettings shellSettings) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
_cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix);
|
_cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(Constants.OutputCacheSettingNamePrefix);
|
||||||
_cacheConfig.Validate();
|
_cacheConfig.Validate();
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
@@ -41,34 +41,42 @@ namespace Orchard.Azure.Services.Caching.Output {
|
|||||||
|
|
||||||
public void Set(string key, CacheItem cacheItem) {
|
public void Set(string key, CacheItem cacheItem) {
|
||||||
Logger.Debug("Set() invoked with key='{0}' in region '{1}'.", key, _region);
|
Logger.Debug("Set() invoked with key='{0}' in region '{1}'.", key, _region);
|
||||||
if (_cacheConfig.IsSharedCaching)
|
if (_cacheConfig.IsSharedCaching) {
|
||||||
_cache.Put(key, cacheItem);
|
_cache.Put(key, cacheItem);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
_cache.Put(key, cacheItem, TimeSpan.FromSeconds(cacheItem.ValidFor), _region);
|
_cache.Put(key, cacheItem, TimeSpan.FromSeconds(cacheItem.ValidFor), _region);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Remove(string key) {
|
public void Remove(string key) {
|
||||||
Logger.Debug("Remove() invoked with key='{0}' in region '{1}'.", key, _region);
|
Logger.Debug("Remove() invoked with key='{0}' in region '{1}'.", key, _region);
|
||||||
if (_cacheConfig.IsSharedCaching)
|
if (_cacheConfig.IsSharedCaching) {
|
||||||
_cache.Remove(key);
|
_cache.Remove(key);
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
_cache.Remove(key, _region);
|
_cache.Remove(key, _region);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void RemoveAll() {
|
public void RemoveAll() {
|
||||||
Logger.Debug("RemoveAll() invoked in region '{0}'.", _region);
|
Logger.Debug("RemoveAll() invoked in region '{0}'.", _region);
|
||||||
if (_cacheConfig.IsSharedCaching)
|
if (_cacheConfig.IsSharedCaching) {
|
||||||
_cache.Clear();
|
_cache.Clear();
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
_cache.ClearRegion(_region);
|
_cache.ClearRegion(_region);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CacheItem GetCacheItem(string key) {
|
public CacheItem GetCacheItem(string key) {
|
||||||
Logger.Debug("GetCacheItem() invoked with key='{0}' in region '{1}'.", key, _region);
|
Logger.Debug("GetCacheItem() invoked with key='{0}' in region '{1}'.", key, _region);
|
||||||
if (_cacheConfig.IsSharedCaching)
|
if (_cacheConfig.IsSharedCaching) {
|
||||||
return _cache.Get(key) as CacheItem;
|
return _cache.Get(key) as CacheItem;
|
||||||
else
|
}
|
||||||
|
else {
|
||||||
return _cache.Get(key, _region) as CacheItem;
|
return _cache.Get(key, _region) as CacheItem;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerable<CacheItem> GetCacheItems(int skip, int count) {
|
public IEnumerable<CacheItem> GetCacheItems(int skip, int count) {
|
||||||
|
@@ -17,5 +17,15 @@ namespace Orchard.Azure.Services.Environment.Configuration {
|
|||||||
var fallbackName = namePrefix + name;
|
var fallbackName = namePrefix + name;
|
||||||
return CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
|
return CloudConfigurationManager.GetSetting(tenantName) ?? CloudConfigurationManager.GetSetting(fallbackName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Reads a setting from platform configuration
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="name">The name of the setting to read.</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, string namePrefix = null) {
|
||||||
|
return CloudConfigurationManager.GetSetting(namePrefix + name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user