Improved logging in Orchard.Azure module.

This commit is contained in:
Daniel Stolt
2013-08-28 02:28:36 +02:00
committed by Sebastien Ros
parent 9c61a70e41
commit f6d01c8d23
5 changed files with 55 additions and 19 deletions

View File

@@ -30,7 +30,7 @@ namespace Orchard.Azure.Services.Caching.Database {
_regionAlphaNumeric = new String(Array.FindAll(_region.ToCharArray(), c => Char.IsLetterOrDigit(c))) + _region.GetHashCode().ToString(); _regionAlphaNumeric = new String(Array.FindAll(_region.ToCharArray(), c => Char.IsLetterOrDigit(c))) + _region.GetHashCode().ToString();
if (_logger.IsDebugEnabled) if (_logger.IsDebugEnabled)
_logger.DebugFormat("Creating instance with CacheName='{0}' and Region='{1}' (original Region='{2}').", cacheName, _regionAlphaNumeric, _region); _logger.DebugFormat("Creating cache with CacheName='{0}' and Region='{1}' (original Region='{2}').", cacheName, _regionAlphaNumeric, _region);
if (!String.IsNullOrEmpty(cacheName)) if (!String.IsNullOrEmpty(cacheName))
_cache = dataCacheFactory.GetCache(cacheName); _cache = dataCacheFactory.GetCache(cacheName);
@@ -101,7 +101,7 @@ namespace Orchard.Azure.Services.Caching.Database {
// The NHibernate locking mechanism and the Azure Cache pessimistic concurrency // The NHibernate locking mechanism and the Azure Cache pessimistic concurrency
// model are not a perfect fit. For example, Azure Cache has atomic "get-and-lock" // model are not a perfect fit. For example, Azure Cache has atomic "get-and-lock"
// and "put-and-unlock" semantics but there is no corresponding atomic operations // and "put-and-unlock" semantics but there are no corresponding atomic operations
// defined on the ICache interface of NHibernate. Also, Azure Cache does not // defined on the ICache interface of NHibernate. Also, Azure Cache does not
// strictly enforce the pessimistic concurrency model - clients are responsible // strictly enforce the pessimistic concurrency model - clients are responsible
// for following the locking protocol and therefore the implementation assumes that // for following the locking protocol and therefore the implementation assumes that

View File

@@ -33,8 +33,10 @@ namespace Orchard.Azure.Services.Caching.Database {
doSave = true; doSave = true;
} }
if (doSave) if (doSave) {
Logger.Information("Added missing shell settings; calling IShellSettingsManager.SaveSettings().");
shellSettingsManager.SaveSettings(shellSettings); shellSettingsManager.SaveSettings(shellSettings);
}
CacheHostIdentifier = shellSettings[Constants.DatabaseCacheHostIdentifierSettingName]; CacheHostIdentifier = shellSettings[Constants.DatabaseCacheHostIdentifierSettingName];
CacheName = shellSettings[Constants.DatabaseCacheCacheNameSettingName]; CacheName = shellSettings[Constants.DatabaseCacheCacheNameSettingName];

View File

@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace Orchard.Azure.Services.Caching.Database.Models {
/// <summary>
/// Fake record in order to force the mappings to be updated
/// once the modules is enabled/disabled.
/// </summary>
public class AzureCacheRecord {
public virtual int Id {
get;
set;
}
}
}

View File

@@ -1,12 +1,12 @@
using Microsoft.ApplicationServer.Caching; using System;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.OutputCache.Models;
using Orchard.OutputCache.Services;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Web; using Microsoft.ApplicationServer.Caching;
using Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.Logging;
using Orchard.OutputCache.Models;
using Orchard.OutputCache.Services;
namespace Orchard.Azure.Services.Caching.Output { namespace Orchard.Azure.Services.Caching.Output {
@@ -31,13 +31,17 @@ namespace Orchard.Azure.Services.Caching.Output {
shellSettings[Constants.OutputCacheIsSharedCachingSettingName] = "false"; shellSettings[Constants.OutputCacheIsSharedCachingSettingName] = "false";
doSave = true; doSave = true;
} }
if (doSave) if (doSave) {
Logger.Information("Added missing shell settings; calling IShellSettingsManager.SaveSettings().");
shellSettingsManager.SaveSettings(shellSettings); shellSettingsManager.SaveSettings(shellSettings);
}
var cacheHostIdentifier = shellSettings[Constants.OutputCacheHostIdentifierSettingName]; var cacheHostIdentifier = shellSettings[Constants.OutputCacheHostIdentifierSettingName];
var cacheName = shellSettings[Constants.OutputCacheCacheNameSettingName]; var cacheName = shellSettings[Constants.OutputCacheCacheNameSettingName];
Logger.Debug("Creating cache with HostIdentifier='{0}', CacheName='{1}'.", cacheHostIdentifier, cacheName);
var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration() { var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration() {
AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, cacheHostIdentifier), AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, cacheHostIdentifier),
MaxConnectionsToServer = 32, MaxConnectionsToServer = 32,
@@ -52,15 +56,16 @@ namespace Orchard.Azure.Services.Caching.Output {
_cache = dataCacheFactory.GetDefaultCache(); _cache = dataCacheFactory.GetDefaultCache();
_usingSharedCaching = Boolean.Parse(shellSettings[Constants.OutputCacheIsSharedCachingSettingName]); _usingSharedCaching = Boolean.Parse(shellSettings[Constants.OutputCacheIsSharedCachingSettingName]);
if (!_usingSharedCaching) if (!_usingSharedCaching) {
{
// If not using Windows Azure Shared Caching we can enable additional features by // If not using Windows Azure Shared Caching we can enable additional features by
// storing all cache items in a region. This enables enumerating and counting all // storing all cache items in a region. This enables enumerating and counting all
// items currently in the cache. // items currently in the cache.
_region = shellSettings.Name; _region = shellSettings.Name;
_cache.CreateRegion(_region); _cache.CreateRegion(_region);
} }
else
Logger.Debug("Configured to use Shared Caching.");
} }
private readonly DataCache _cache; private readonly DataCache _cache;
@@ -68,6 +73,7 @@ namespace Orchard.Azure.Services.Caching.Output {
private readonly string _region; private readonly string _region;
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);
if (_usingSharedCaching) if (_usingSharedCaching)
_cache.Put(key, cacheItem); _cache.Put(key, cacheItem);
else else
@@ -75,6 +81,7 @@ namespace Orchard.Azure.Services.Caching.Output {
} }
public void Remove(string key) { public void Remove(string key) {
Logger.Debug("Remove() invoked with key='{0}' in region '{1}'.", key, _region);
if (_usingSharedCaching) if (_usingSharedCaching)
_cache.Remove(key); _cache.Remove(key);
else else
@@ -82,6 +89,7 @@ namespace Orchard.Azure.Services.Caching.Output {
} }
public void RemoveAll() { public void RemoveAll() {
Logger.Debug("RemoveAll() invoked in region '{0}'.", _region);
if (_usingSharedCaching) if (_usingSharedCaching)
_cache.Clear(); _cache.Clear();
else else
@@ -89,6 +97,7 @@ namespace Orchard.Azure.Services.Caching.Output {
} }
public CacheItem GetCacheItem(string key) { public CacheItem GetCacheItem(string key) {
Logger.Debug("GetCacheItem() invoked with key='{0}' in region '{1}'.", key, _region);
if (_usingSharedCaching) if (_usingSharedCaching)
return _cache.Get(key) as CacheItem; return _cache.Get(key) as CacheItem;
else else
@@ -96,8 +105,11 @@ namespace Orchard.Azure.Services.Caching.Output {
} }
public IEnumerable<CacheItem> GetCacheItems(int skip, int count) { public IEnumerable<CacheItem> GetCacheItems(int skip, int count) {
if (_usingSharedCaching) Logger.Debug("GetCacheItems() invoked in region '{0}'.", _region);
if (_usingSharedCaching) {
Logger.Debug("Enumeration not supported with Shared Caching; returning empty enumerable.");
return Enumerable.Empty<CacheItem>(); // Enumeration not supported with Shared Caching. return Enumerable.Empty<CacheItem>(); // Enumeration not supported with Shared Caching.
}
return _cache.GetObjectsInRegion(_region).AsParallel() return _cache.GetObjectsInRegion(_region).AsParallel()
.Select(x => x.Value) .Select(x => x.Value)
@@ -108,8 +120,11 @@ namespace Orchard.Azure.Services.Caching.Output {
} }
public int GetCacheItemsCount() { public int GetCacheItemsCount() {
if (_usingSharedCaching) Logger.Debug("GetCacheItemsCount() invoked in region '{0}'.", _region);
if (_usingSharedCaching) {
Logger.Debug("Enumeration not supported with Shared Caching; returning zero.");
return 0; // Enumeration not supported with Shared Caching. return 0; // Enumeration not supported with Shared Caching.
}
return _cache.GetObjectsInRegion(_region).AsParallel() return _cache.GetObjectsInRegion(_region).AsParallel()
.Select(x => x.Value) .Select(x => x.Value)

View File

@@ -24,7 +24,8 @@ namespace Orchard.Azure.Services.Environment.Configuration {
private readonly AzureFileSystem _fileSystem; private readonly AzureFileSystem _fileSystem;
private readonly IShellSettingsManagerEventHandler _events; private readonly IShellSettingsManagerEventHandler _events;
public AzureBlobShellSettingsManager(IMimeTypeProvider mimeTypeProvider, IShellSettingsManagerEventHandler events) { public AzureBlobShellSettingsManager(IMimeTypeProvider mimeTypeProvider, IShellSettingsManagerEventHandler events)
: base() {
_fileSystem = new AzureFileSystem(CloudConfigurationManager.GetSetting(Constants.ShellSettingsStorageConnectionStringSettingName), Constants.ShellSettingsContainerName, String.Empty, true, mimeTypeProvider); _fileSystem = new AzureFileSystem(CloudConfigurationManager.GetSetting(Constants.ShellSettingsStorageConnectionStringSettingName), Constants.ShellSettingsContainerName, String.Empty, true, mimeTypeProvider);
_events = events; _events = events;
} }