#19122: Added ICache.IsValid and ICache.TryGet methods.

Work Item: 19122

--HG--
branch : 1.x
This commit is contained in:
Piotr Szmyd
2012-10-10 22:37:13 +02:00
parent 076fd3fb60
commit bda2dfb127
2 changed files with 20 additions and 0 deletions

View File

@@ -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);

View File

@@ -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);
}
}