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;
|
||||||
|
using System.Collections.Concurrent;
|
||||||
|
|
||||||
namespace Orchard.Caching {
|
namespace Orchard.Caching {
|
||||||
public interface ICacheManager {
|
public interface ICacheManager {
|
||||||
@@ -7,9 +8,13 @@ namespace Orchard.Caching {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static class CacheManagerExtensions {
|
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) {
|
public static TResult Get<TKey, TResult>(this ICacheManager cacheManager, TKey key, bool preventConcurrentCalls, Func<AcquireContext<TKey>, TResult> acquire) {
|
||||||
if (preventConcurrentCalls) {
|
if (preventConcurrentCalls) {
|
||||||
lock(key) {
|
var lockKey = _locks.GetOrAdd(key, _ => new object());
|
||||||
|
lock (lockKey) {
|
||||||
return cacheManager.Get(key, acquire);
|
return cacheManager.Get(key, acquire);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user