Merge branch '1.8.x' into 1.x

This commit is contained in:
Sebastien Ros 2014-04-21 16:01:27 -07:00
commit 5365d329fc
3 changed files with 17 additions and 17 deletions

View File

@ -40,9 +40,8 @@ namespace Orchard.Azure.Services.Caching {
}
}
public DataCache CreateCache() {
public DataCacheFactory CreateCache() {
var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration {
MaxConnectionsToServer = 32,
UseLegacyProtocol = false,
IsCompressionEnabled = CompressionIsEnabled
};
@ -51,13 +50,9 @@ namespace Orchard.Azure.Services.Caching {
if (!String.IsNullOrEmpty(AuthorizationToken))
dataCacheFactoryConfiguration.SecurityProperties = new DataCacheSecurity(AuthorizationToken, sslEnabled: false);
var dataCacheFactory = new DataCacheFactory(dataCacheFactoryConfiguration);
if (!String.IsNullOrEmpty(CacheName)) {
return dataCacheFactory.GetCache(CacheName);
}
return dataCacheFactory.GetDefaultCache();
return new DataCacheFactory(dataCacheFactoryConfiguration);
}
public override int GetHashCode() {

View File

@ -9,6 +9,7 @@ namespace Orchard.Azure.Services.Caching.Database {
public class AzureCacheProvider : ICacheProvider {
private DataCache _dataCache;
private DataCacheFactory _dataCacheFactory;
public ICache BuildCache(string regionName, IDictionary<string, string> properties) {
@ -49,11 +50,13 @@ namespace Orchard.Azure.Services.Caching.Database {
throw new Exception(String.Format("The {0} configuration settings are missing or invalid.", Constants.DatabaseCacheFeatureName), ex);
}
_dataCache = configuration.CreateCache();
_dataCacheFactory = configuration.CreateCache();
_dataCache = _dataCacheFactory.GetDefaultCache();
}
public void Stop() {
_dataCache = null;
_dataCacheFactory.Dispose();
}
}
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using Microsoft.ApplicationServer.Caching;
@ -23,7 +22,7 @@ namespace Orchard.Azure.Services.Caching.Output {
public const int Retries = 2;
private CacheClientConfiguration _cacheClientConfiguration;
private static ConcurrentDictionary<CacheClientConfiguration, DataCache> _dataCaches = new ConcurrentDictionary<CacheClientConfiguration, DataCache>();
private static ConcurrentDictionary<CacheClientConfiguration, DataCacheFactory> _dataCacheFactories = new ConcurrentDictionary<CacheClientConfiguration, DataCacheFactory>();
private static ConcurrentBag<string> _regions = new ConcurrentBag<string>();
private readonly string _regionAlphaNumeric;
@ -84,12 +83,13 @@ namespace Orchard.Azure.Services.Caching.Output {
public DataCache Cache {
get {
var cache = _dataCaches.GetOrAdd(CacheConfiguration, cfg => {
var cacheFactory = _dataCacheFactories.GetOrAdd(CacheConfiguration, cfg => {
Logger.Debug("Creating a new cache client ({0})", CacheConfiguration.GetHashCode());
return cfg.CreateCache();
});
var cache = String.IsNullOrEmpty(CacheConfiguration.CacheName) ? cacheFactory.GetDefaultCache() : cacheFactory.GetCache(CacheConfiguration.CacheName);
// creating a region uses a network call, try to optimise it
if (!_regions.Contains(_regionAlphaNumeric)) {
Logger.Debug("Creating a new region: {0}", _regionAlphaNumeric);
@ -122,9 +122,11 @@ namespace Orchard.Azure.Services.Caching.Output {
return function.Invoke();
}
catch (DataCacheException) {
DataCache cache;
DataCacheFactory cacheFactory;
Logger.Debug("Retrying cache operation");
_dataCaches.TryRemove(CacheConfiguration, out cache);
if (_dataCacheFactories.TryRemove(CacheConfiguration, out cacheFactory)) {
cacheFactory.Dispose();
}
return Retry(function, times--);
}
}