Add lock around config serialization

The lock avoids concurrent access to the cached configuration.

--HG--
branch : dev
This commit is contained in:
Renaud Paquay
2010-07-18 21:43:21 -07:00
parent f4079a9301
commit 3c6c58fa84

View File

@@ -14,6 +14,7 @@ namespace Orchard.Data {
private readonly ShellSettings _shellSettings; private readonly ShellSettings _shellSettings;
private readonly ShellBlueprint _shellBlueprint; private readonly ShellBlueprint _shellBlueprint;
private readonly IAppDataFolder _appDataFolder; private readonly IAppDataFolder _appDataFolder;
private readonly object _syncRoot = new object();
public SessionConfigurationCache(ShellSettings shellSettings, ShellBlueprint shellBlueprint, IAppDataFolder appDataFolder) { public SessionConfigurationCache(ShellSettings shellSettings, ShellBlueprint shellBlueprint, IAppDataFolder appDataFolder) {
_shellSettings = shellSettings; _shellSettings = shellSettings;
@@ -30,9 +31,11 @@ namespace Orchard.Data {
// Return previous configuration if it exsists and has the same hash as // Return previous configuration if it exsists and has the same hash as
// the current blueprint. // the current blueprint.
var previousConfig = ReadConfiguration(hash); lock (_syncRoot) {
if (previousConfig != null) { var previousConfig = ReadConfiguration(hash);
return previousConfig.Configuration; if (previousConfig != null) {
return previousConfig.Configuration;
}
} }
// Create cache and persist it // Create cache and persist it
@@ -41,7 +44,9 @@ namespace Orchard.Data {
Configuration = builder() Configuration = builder()
}; };
StoreConfiguration(cache); lock (_syncRoot) {
StoreConfiguration(cache);
}
return cache.Configuration; return cache.Configuration;
} }