--HG--
branch : 1.x
This commit is contained in:
Sebastien Ros
2011-03-31 18:05:08 -07:00
3 changed files with 25 additions and 7 deletions

View File

@@ -27,6 +27,10 @@ namespace Orchard.WarmupStarter {
public static void Signal() { public static void Signal() {
lock(typeof(WarmupHttpModule)) { lock(typeof(WarmupHttpModule)) {
if (_awaiting == null) {
return;
}
var awaiting = _awaiting; var awaiting = _awaiting;
_awaiting = null; _awaiting = null;
foreach (var action in awaiting) { foreach (var action in awaiting) {

View File

@@ -74,7 +74,7 @@ namespace Orchard.Data.Migration {
var migrations = GetDataMigrations(feature); var migrations = GetDataMigrations(feature);
// apply update methods to each migration class for the module)))) // apply update methods to each migration class for the module
foreach ( var migration in migrations ) { foreach ( var migration in migrations ) {
// copy the objet for the Linq query // copy the objet for the Linq query
var tempMigration = migration; var tempMigration = migration;

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
using NHibernate.Cfg; using NHibernate.Cfg;
using Orchard.Environment; using Orchard.Environment;
@@ -16,12 +17,14 @@ namespace Orchard.Data {
private readonly ShellBlueprint _shellBlueprint; private readonly ShellBlueprint _shellBlueprint;
private readonly IAppDataFolder _appDataFolder; private readonly IAppDataFolder _appDataFolder;
private readonly IHostEnvironment _hostEnvironment; private readonly IHostEnvironment _hostEnvironment;
private ConfigurationCache _currentConfig;
public SessionConfigurationCache(ShellSettings shellSettings, ShellBlueprint shellBlueprint, IAppDataFolder appDataFolder, IHostEnvironment hostEnvironment) { public SessionConfigurationCache(ShellSettings shellSettings, ShellBlueprint shellBlueprint, IAppDataFolder appDataFolder, IHostEnvironment hostEnvironment) {
_shellSettings = shellSettings; _shellSettings = shellSettings;
_shellBlueprint = shellBlueprint; _shellBlueprint = shellBlueprint;
_appDataFolder = appDataFolder; _appDataFolder = appDataFolder;
_hostEnvironment = hostEnvironment; _hostEnvironment = hostEnvironment;
_currentConfig = null;
Logger = NullLogger.Instance; Logger = NullLogger.Instance;
} }
@@ -31,21 +34,27 @@ namespace Orchard.Data {
public Configuration GetConfiguration(Func<Configuration> builder) { public Configuration GetConfiguration(Func<Configuration> builder) {
var hash = ComputeHash().Value; var hash = ComputeHash().Value;
// Return previous configuration if it exsists and has the same hash as // if the current configuration is unchanged, return it
if(_currentConfig != null && _currentConfig.Hash == hash) {
return _currentConfig.Configuration;
}
// Return previous configuration if it exists and has the same hash as
// the current blueprint. // the current blueprint.
var previousConfig = ReadConfiguration(hash); var previousConfig = ReadConfiguration(hash);
if (previousConfig != null) { if (previousConfig != null) {
_currentConfig = previousConfig;
return previousConfig.Configuration; return previousConfig.Configuration;
} }
// Create cache and persist it // Create cache and persist it
var cache = new ConfigurationCache { _currentConfig = new ConfigurationCache {
Hash = hash, Hash = hash,
Configuration = builder() Configuration = builder()
}; };
StoreConfiguration(cache); StoreConfiguration(_currentConfig);
return cache.Configuration; return _currentConfig.Configuration;
} }
private class ConfigurationCache { private class ConfigurationCache {
@@ -66,11 +75,11 @@ namespace Orchard.Data {
formatter.Serialize(stream, cache.Configuration); formatter.Serialize(stream, cache.Configuration);
} }
} }
catch (Exception e) { catch (SerializationException e) {
//Note: This can happen when multiple processes/AppDomains try to save //Note: This can happen when multiple processes/AppDomains try to save
// the cached configuration at the same time. Only one concurrent // the cached configuration at the same time. Only one concurrent
// writer will win, and it's harmless for the other ones to fail. // writer will win, and it's harmless for the other ones to fail.
for (var scan = e; scan != null; scan = scan.InnerException) for (Exception scan = e; scan != null; scan = scan.InnerException)
Logger.Warning("Error storing new NHibernate cache configuration: {0}", scan.Message); Logger.Warning("Error storing new NHibernate cache configuration: {0}", scan.Message);
} }
} }
@@ -88,6 +97,11 @@ namespace Orchard.Data {
var formatter = new BinaryFormatter(); var formatter = new BinaryFormatter();
using (var stream = _appDataFolder.OpenFile(pathName)) { using (var stream = _appDataFolder.OpenFile(pathName)) {
// if the stream is empty, stop here
if(stream.Length == 0) {
return null;
}
var oldHash = (string)formatter.Deserialize(stream); var oldHash = (string)formatter.Deserialize(stream);
if (hash != oldHash) { if (hash != oldHash) {
Logger.Information("The cached NHibernate configuration is out of date. A new one will be re-generated."); Logger.Information("The cached NHibernate configuration is out of date. A new one will be re-generated.");