@@ -15,6 +15,8 @@ namespace SmartStore.Core.Caching
1515{
1616 public partial class MemoryCacheManager : DisposableObject , ICacheManager
1717 {
18+ const string LockRecursionExceptionMessage = "Acquiring identical cache items recursively is not supported. Key: {0}" ;
19+
1820 // Wwe put a special string into cache if value is null,
1921 // otherwise our 'Contains()' would always return false,
2022 // which is bad if we intentionally wanted to save NULL values.
@@ -79,8 +81,14 @@ public T Get<T>(string key, Func<T> acquirer, TimeSpan? duration = null, bool in
7981 return value ;
8082 }
8183
84+ var lockKey = "cache:" + key ;
85+ if ( KeyedLock . IsLockHeld ( lockKey ) )
86+ {
87+ throw new LockRecursionException ( LockRecursionExceptionMessage . FormatInvariant ( key ) ) ;
88+ }
89+
8290 // Get the (semaphore) locker specific to this key
83- using ( KeyedLock . Lock ( key ) )
91+ using ( KeyedLock . Lock ( lockKey , TimeSpan . FromMinutes ( 1 ) ) )
8492 {
8593 // Atomic operation must be outer locked
8694 if ( ! TryGet ( key , independent , out value ) )
@@ -104,8 +112,14 @@ public async Task<T> GetAsync<T>(string key, Func<Task<T>> acquirer, TimeSpan? d
104112 return value ;
105113 }
106114
115+ var lockKey = "cache:" + key ;
116+ if ( KeyedLock . IsLockHeld ( lockKey ) )
117+ {
118+ throw new LockRecursionException ( LockRecursionExceptionMessage . FormatInvariant ( key ) ) ;
119+ }
120+
107121 // Get the async (semaphore) locker specific to this key
108- using ( await KeyedLock . LockAsync ( key ) )
122+ using ( await KeyedLock . LockAsync ( lockKey , TimeSpan . FromMinutes ( 1 ) ) )
109123 {
110124 if ( ! TryGet ( key , independent , out value ) )
111125 {
0 commit comments