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:
Sebastien Ros 2013-08-30 15:01:23 -07:00
parent a567a99cd4
commit 760269c900
4 changed files with 35 additions and 17 deletions

View File

@ -6,15 +6,15 @@ namespace Orchard.Azure.Services.Caching {
public class CacheClientConfiguration {
public static CacheClientConfiguration FromPlatformConfiguration(string tenant, string settingNamePrefix) {
var portString = PlatformConfiguration.GetSetting(Constants.CachePortSettingName, tenant, settingNamePrefix);
var isSharedCachingString = PlatformConfiguration.GetSetting(Constants.CacheIsSharedCachingSettingName, tenant, settingNamePrefix);
public static CacheClientConfiguration FromPlatformConfiguration(string settingNamePrefix) {
var portString = PlatformConfiguration.GetSetting(Constants.CachePortSettingName, settingNamePrefix);
var isSharedCachingString = PlatformConfiguration.GetSetting(Constants.CacheIsSharedCachingSettingName, settingNamePrefix);
return new CacheClientConfiguration {
HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, tenant, settingNamePrefix),
CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, tenant, settingNamePrefix),
Hostname = PlatformConfiguration.GetSetting(Constants.CacheHostnameSettingName, tenant, settingNamePrefix),
HostIdentifier = PlatformConfiguration.GetSetting(Constants.CacheHostIdentifierSettingName, settingNamePrefix),
CacheName = PlatformConfiguration.GetSetting(Constants.CacheCacheNameSettingName, settingNamePrefix),
Hostname = PlatformConfiguration.GetSetting(Constants.CacheHostnameSettingName, settingNamePrefix),
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)
};
}

View File

@ -10,7 +10,7 @@ namespace Orchard.Azure.Services.Caching.Database {
CacheClientConfiguration configuration;
try {
configuration = CacheClientConfiguration.FromPlatformConfiguration(regionName, Constants.DatabaseCacheSettingNamePrefix);
configuration = CacheClientConfiguration.FromPlatformConfiguration(Constants.DatabaseCacheSettingNamePrefix);
configuration.Validate();
}
catch (Exception ex) {

View File

@ -17,7 +17,7 @@ namespace Orchard.Azure.Services.Caching.Output {
public AzureOutputCacheStorageProvider(ShellSettings shellSettings) {
try {
_cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(shellSettings.Name, Constants.OutputCacheSettingNamePrefix);
_cacheConfig = CacheClientConfiguration.FromPlatformConfiguration(Constants.OutputCacheSettingNamePrefix);
_cacheConfig.Validate();
}
catch (Exception ex) {
@ -41,34 +41,42 @@ namespace Orchard.Azure.Services.Caching.Output {
public void Set(string key, CacheItem cacheItem) {
Logger.Debug("Set() invoked with key='{0}' in region '{1}'.", key, _region);
if (_cacheConfig.IsSharedCaching)
if (_cacheConfig.IsSharedCaching) {
_cache.Put(key, cacheItem);
else
}
else {
_cache.Put(key, cacheItem, TimeSpan.FromSeconds(cacheItem.ValidFor), _region);
}
}
public void Remove(string key) {
Logger.Debug("Remove() invoked with key='{0}' in region '{1}'.", key, _region);
if (_cacheConfig.IsSharedCaching)
if (_cacheConfig.IsSharedCaching) {
_cache.Remove(key);
else
}
else {
_cache.Remove(key, _region);
}
}
public void RemoveAll() {
Logger.Debug("RemoveAll() invoked in region '{0}'.", _region);
if (_cacheConfig.IsSharedCaching)
if (_cacheConfig.IsSharedCaching) {
_cache.Clear();
else
}
else {
_cache.ClearRegion(_region);
}
}
public CacheItem GetCacheItem(string key) {
Logger.Debug("GetCacheItem() invoked with key='{0}' in region '{1}'.", key, _region);
if (_cacheConfig.IsSharedCaching)
if (_cacheConfig.IsSharedCaching) {
return _cache.Get(key) as CacheItem;
else
}
else {
return _cache.Get(key, _region) as CacheItem;
}
}
public IEnumerable<CacheItem> GetCacheItems(int skip, int count) {

View File

@ -17,5 +17,15 @@ namespace Orchard.Azure.Services.Environment.Configuration {
var fallbackName = namePrefix + name;
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);
}
}
}