Skip to content

Instantly share code, notes, and snippets.

@thecodejunkie
Created June 7, 2011 09:15
public class DefaultViewCache : IViewCache
{
private readonly ConcurrentDictionary<ViewLocationResult, object> cache;
public DefaultViewCache()
{
this.cache = new ConcurrentDictionary<ViewLocationResult, object>();
}
public TCompiledView GetOrAdd<TCompiledView>(ViewLocationResult viewLocationResult, Func<ViewLocationResult, TCompiledView> valueFactory)
{
object result;
if (!this.cache.TryGetValue(viewLocationResult, out result))
{
result = valueFactory.Invoke(viewLocationResult);
this.cache.GetOrAdd(viewLocationResult, result);
}
return (TCompiledView)result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment