mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-12-03 12:03:51 +08:00
Add lock around config serialization
The lock avoids concurrent access to the cached configuration. --HG-- branch : dev
This commit is contained in:
@@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user