Brought back support for compression in Azure database caching.

This commit is contained in:
Daniel Stolt
2013-08-31 13:52:06 +02:00
committed by Sebastien Ros
parent 1edff1f34c
commit 4f47c6a967
2 changed files with 16 additions and 12 deletions

View File

@@ -51,7 +51,7 @@ namespace Orchard.Azure.Services.Caching {
public bool CompressionIsEnabled { public bool CompressionIsEnabled {
get; get;
protected set; set;
} }
public bool AutodiscoverIsEnabled { public bool AutodiscoverIsEnabled {
@@ -77,7 +77,8 @@ namespace Orchard.Azure.Services.Caching {
dataCacheFactoryConfiguration.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, HostIdentifier); dataCacheFactoryConfiguration.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, HostIdentifier);
} }
else { else {
dataCacheFactoryConfiguration.Servers = new[] {new DataCacheServerEndpoint(Hostname, Port)}; dataCacheFactoryConfiguration.AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(false);
dataCacheFactoryConfiguration.Servers = new[] { new DataCacheServerEndpoint(Hostname, Port) };
dataCacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(AuthorizationToken); dataCacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(AuthorizationToken);
} }

View File

@@ -8,25 +8,21 @@ namespace Orchard.Azure.Services.Caching.Database {
public class AzureCacheProvider : ICacheProvider { public class AzureCacheProvider : ICacheProvider {
private DataCache _dataCache; private DataCache _dataCache;
private bool _sharedCaching; private bool _isSharedCaching;
public ICache BuildCache(string regionName, IDictionary<string, string> properties) { public ICache BuildCache(string regionName, IDictionary<string, string> properties) {
if (_dataCache == null) { if (_dataCache == null) {
throw new ApplicationException("DataCache should be available"); throw new InvalidOperationException("Can't call this method when provider is in stopped state.");
} }
string enableCompressionString;
properties.TryGetValue("compression_enabled", out enableCompressionString);
TimeSpan? expiration = null; TimeSpan? expiration = null;
string expirationString; string expirationString;
if (properties.TryGetValue(NHibernate.Cfg.Environment.CacheDefaultExpiration, out expirationString) || properties.TryGetValue("cache.default_expiration", out expirationString)) { if (properties.TryGetValue(NHibernate.Cfg.Environment.CacheDefaultExpiration, out expirationString) || properties.TryGetValue("cache.default_expiration", out expirationString)) {
expiration = TimeSpan.FromSeconds(Int32.Parse(expirationString)); expiration = TimeSpan.FromSeconds(Int32.Parse(expirationString));
} }
return new AzureCacheClient(_dataCache, _sharedCaching, regionName, expiration); return new AzureCacheClient(_dataCache, _isSharedCaching, regionName, expiration);
} }
public long NextTimestamp() { public long NextTimestamp() {
@@ -37,9 +33,15 @@ namespace Orchard.Azure.Services.Caching.Database {
CacheClientConfiguration configuration; CacheClientConfiguration configuration;
try { try {
var tenant = properties["cache.region_prefix"]; var tenantName = properties["cache.region_prefix"];
configuration = CacheClientConfiguration.FromPlatformConfiguration(tenant, Constants.DatabaseCacheSettingNamePrefix); bool enableCompression = false;
string enableCompressionString;
if (properties.TryGetValue("compression_enabled", out enableCompressionString))
enableCompression = Boolean.Parse(enableCompressionString);
configuration = CacheClientConfiguration.FromPlatformConfiguration(tenantName, Constants.DatabaseCacheSettingNamePrefix);
configuration.CompressionIsEnabled = enableCompression;
configuration.Validate(); configuration.Validate();
} }
catch (Exception ex) { catch (Exception ex) {
@@ -47,10 +49,11 @@ namespace Orchard.Azure.Services.Caching.Database {
} }
_dataCache = configuration.CreateCache(); _dataCache = configuration.CreateCache();
_sharedCaching = configuration.IsSharedCaching; _isSharedCaching = configuration.IsSharedCaching;
} }
public void Stop() { public void Stop() {
_dataCache = null;
} }
} }
} }