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();
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))
_cache = dataCacheFactory.GetCache(cacheName);
@ -101,7 +101,7 @@ namespace Orchard.Azure.Services.Caching.Database {
// 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"
// 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
// strictly enforce the pessimistic concurrency model - clients are responsible
// 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;
}
if (doSave)
if (doSave) {
Logger.Information("Added missing shell settings; calling IShellSettingsManager.SaveSettings().");
shellSettingsManager.SaveSettings(shellSettings);
}
CacheHostIdentifier = shellSettings[Constants.DatabaseCacheHostIdentifierSettingName];
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 Orchard.Environment.Configuration;
using Orchard.Environment.Extensions;
using Orchard.OutputCache.Models;
using Orchard.OutputCache.Services;
using System;
using System;
using System.Collections.Generic;
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 {
@ -31,13 +31,17 @@ namespace Orchard.Azure.Services.Caching.Output {
shellSettings[Constants.OutputCacheIsSharedCachingSettingName] = "false";
doSave = true;
}
if (doSave)
if (doSave) {
Logger.Information("Added missing shell settings; calling IShellSettingsManager.SaveSettings().");
shellSettingsManager.SaveSettings(shellSettings);
}
var cacheHostIdentifier = shellSettings[Constants.OutputCacheHostIdentifierSettingName];
var cacheName = shellSettings[Constants.OutputCacheCacheNameSettingName];
Logger.Debug("Creating cache with HostIdentifier='{0}', CacheName='{1}'.", cacheHostIdentifier, cacheName);
var dataCacheFactoryConfiguration = new DataCacheFactoryConfiguration() {
AutoDiscoverProperty = new DataCacheAutoDiscoverProperty(true, cacheHostIdentifier),
MaxConnectionsToServer = 32,
@ -52,15 +56,16 @@ namespace Orchard.Azure.Services.Caching.Output {
_cache = dataCacheFactory.GetDefaultCache();
_usingSharedCaching = Boolean.Parse(shellSettings[Constants.OutputCacheIsSharedCachingSettingName]);
if (!_usingSharedCaching)
{
if (!_usingSharedCaching) {
// 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
// items currently in the cache.
_region = shellSettings.Name;
_cache.CreateRegion(_region);
_cache.CreateRegion(_region);
}
else
Logger.Debug("Configured to use Shared Caching.");
}
private readonly DataCache _cache;
@ -68,6 +73,7 @@ namespace Orchard.Azure.Services.Caching.Output {
private readonly string _region;
public void Set(string key, CacheItem cacheItem) {
Logger.Debug("Set() invoked with key='{0}' in region '{1}'.", key, _region);
if (_usingSharedCaching)
_cache.Put(key, cacheItem);
else
@ -75,6 +81,7 @@ namespace Orchard.Azure.Services.Caching.Output {
}
public void Remove(string key) {
Logger.Debug("Remove() invoked with key='{0}' in region '{1}'.", key, _region);
if (_usingSharedCaching)
_cache.Remove(key);
else
@ -82,6 +89,7 @@ namespace Orchard.Azure.Services.Caching.Output {
}
public void RemoveAll() {
Logger.Debug("RemoveAll() invoked in region '{0}'.", _region);
if (_usingSharedCaching)
_cache.Clear();
else
@ -89,6 +97,7 @@ namespace Orchard.Azure.Services.Caching.Output {
}
public CacheItem GetCacheItem(string key) {
Logger.Debug("GetCacheItem() invoked with key='{0}' in region '{1}'.", key, _region);
if (_usingSharedCaching)
return _cache.Get(key) as CacheItem;
else
@ -96,8 +105,11 @@ namespace Orchard.Azure.Services.Caching.Output {
}
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 _cache.GetObjectsInRegion(_region).AsParallel()
.Select(x => x.Value)
@ -108,8 +120,11 @@ namespace Orchard.Azure.Services.Caching.Output {
}
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 _cache.GetObjectsInRegion(_region).AsParallel()
.Select(x => x.Value)

View File

@ -24,7 +24,8 @@ namespace Orchard.Azure.Services.Environment.Configuration {
private readonly AzureFileSystem _fileSystem;
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);
_events = events;
}