mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
#19122: Added ICache.IsValid and ICache.TryGet methods.
Work Item: 19122 --HG-- branch : 1.x
This commit is contained in:
@@ -23,6 +23,24 @@ namespace Orchard.Caching {
|
||||
return entry.Result;
|
||||
}
|
||||
|
||||
public bool TryGet(TKey key, out TResult value){
|
||||
CacheEntry cacheEntry;
|
||||
if (_entries.TryGetValue(key, out cacheEntry)){
|
||||
value = cacheEntry.Result;
|
||||
return true;
|
||||
}
|
||||
value = default(TResult);
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool IsValid(TKey key){
|
||||
CacheEntry currentEntry;
|
||||
if (_entries.TryGetValue(key, out currentEntry)){
|
||||
return currentEntry.Tokens.Any(t => !t.IsCurrent);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private CacheEntry AddEntry(TKey k, Func<AcquireContext<TKey>, TResult> acquire) {
|
||||
var entry = CreateEntry(k, acquire);
|
||||
PropagateTokens(entry);
|
||||
|
@@ -3,5 +3,7 @@
|
||||
namespace Orchard.Caching {
|
||||
public interface ICache<TKey, TResult> {
|
||||
TResult Get(TKey key, Func<AcquireContext<TKey>, TResult> acquire);
|
||||
bool IsValid(TKey key);
|
||||
bool TryGet(TKey key, out TResult value);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user