mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-04-05 21:01:35 +08:00
Add lock around config serialization
The lock avoids concurrent access to the cached configuration. --HG-- branch : dev
This commit is contained in:
parent
f4079a9301
commit
3c6c58fa84
@ -14,6 +14,7 @@ namespace Orchard.Data {
|
||||
private readonly ShellSettings _shellSettings;
|
||||
private readonly ShellBlueprint _shellBlueprint;
|
||||
private readonly IAppDataFolder _appDataFolder;
|
||||
private readonly object _syncRoot = new object();
|
||||
|
||||
public SessionConfigurationCache(ShellSettings shellSettings, ShellBlueprint shellBlueprint, IAppDataFolder appDataFolder) {
|
||||
_shellSettings = shellSettings;
|
||||
@ -30,9 +31,11 @@ namespace Orchard.Data {
|
||||
|
||||
// Return previous configuration if it exsists and has the same hash as
|
||||
// the current blueprint.
|
||||
var previousConfig = ReadConfiguration(hash);
|
||||
if (previousConfig != null) {
|
||||
return previousConfig.Configuration;
|
||||
lock (_syncRoot) {
|
||||
var previousConfig = ReadConfiguration(hash);
|
||||
if (previousConfig != null) {
|
||||
return previousConfig.Configuration;
|
||||
}
|
||||
}
|
||||
|
||||
// Create cache and persist it
|
||||
@ -41,7 +44,9 @@ namespace Orchard.Data {
|
||||
Configuration = builder()
|
||||
};
|
||||
|
||||
StoreConfiguration(cache);
|
||||
lock (_syncRoot) {
|
||||
StoreConfiguration(cache);
|
||||
}
|
||||
return cache.Configuration;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user