Sdl.Web.Tridion/Providers/Caching/DD4TCacheProvider.cs
/// <summary>
/// Tries to get a cached value for a given key and cache region.
/// </summary>
/// <param name="key">The key.</param>
/// <param name="region">The name of the cache region. Different cache regions can have different retention policies.</param>
/// <param name="value">The cached value (output).</param>
/// <typeparam name="T">The type of the value to get.</typeparam>
/// <returns><c>true</c> if a cached value was found for the given key and cache region.</returns>
Tries to get a cached value for a given key and cache region.
Tries to get a cached value for a given key and cache region .
public override bool TryGet<T>(string key, string region, out T value)
        {
            string cacheAgentKey = GetQualifiedKey(key, region);
            object cachedValue = _cacheAgent.Load(cacheAgentKey);
            if (cachedValue == null)
            {
                bool valueAdded = AwaitAddingValue(key, region);
                if (valueAdded)
                {
                    cachedValue = _cacheAgent.Load(cacheAgentKey);
                }
                if (cachedValue == null)
                {
                    Log.Debug("No value cached for key '{0}' in region '{1}'.", key, region);
                    value = default(T);
                    return false;
                }
            }
            if (!(cachedValue is T))
            {
                throw new DxaException(
                    $"Cached value for key '{key}' in region '{region}' is of type {cachedValue.GetType().FullName} instead of {typeof (T).FullName}."
                    );
            }
            value = (T)cachedValue;
            return true;
        }
public override bool TryGet < T > ( string key , string region , out T value ) { string cacheAgentKey = GetQualifiedKey ( key , region ) ; object cachedValue = _cacheAgent . Load ( cacheAgentKey ) ; if ( cachedValue == null ) { bool valueAdded = AwaitAddingValue ( key , region ) ; if ( valueAdded ) { cachedValue = _cacheAgent . Load ( cacheAgentKey ) ; } if ( cachedValue == null ) { Log . Debug ( " " , key , region ) ; value = default ( T ) ; return false ; } } if ( ! ( cachedValue is T ) ) { throw new DxaException ( $" Cached value for key ' { key } ' in region ' { region } ' is of type  { cachedValue . GetType ( ) . FullName }  instead of  { typeof ( T ) . FullName } . " ) ; } value = ( T ) cachedValue ; return true ; }
Tries to get a cached value for a given key and cache region.
Tries to get a cached value for a given key and cache region .
// Maybe another thread is just adding a value for the key/region... // Another thread has just added a value for the key/region. Retry.
None
key
string
None
region
string
The name of the cache region. Different cache regions can have different retention policies.
The name of the cache region . Different cache regions can have different retention policies .
T
out
value
The cached value (output).
The cached value ( output ) .
typeparam
The type of the value to get.
The type of the value to get .