mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-08 00:14:31 +08:00
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
|
||||
namespace Orchard.Caching {
|
||||
public interface ICacheManager {
|
||||
@@ -7,9 +8,13 @@ namespace Orchard.Caching {
|
||||
}
|
||||
|
||||
public static class CacheManagerExtensions {
|
||||
|
||||
private static readonly ConcurrentDictionary<object, object> _locks = new ConcurrentDictionary<object, object>();
|
||||
|
||||
public static TResult Get<TKey, TResult>(this ICacheManager cacheManager, TKey key, bool preventConcurrentCalls, Func<AcquireContext<TKey>, TResult> acquire) {
|
||||
if (preventConcurrentCalls) {
|
||||
lock(key) {
|
||||
var lockKey = _locks.GetOrAdd(key, _ => new object());
|
||||
lock (lockKey) {
|
||||
return cacheManager.Get(key, acquire);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user