本文整理汇总了C#中ITemplateKey.GetUniqueKeyString方法的典型用法代码示例。如果您正苦于以下问题:C# ITemplateKey.GetUniqueKeyString方法的具体用法?C# ITemplateKey.GetUniqueKeyString怎么用?C# ITemplateKey.GetUniqueKeyString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITemplateKey
的用法示例。
在下文中一共展示了ITemplateKey.GetUniqueKeyString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CacheTemplateHelper
private void CacheTemplateHelper(ICompiledTemplate template, ITemplateKey templateKey, Type modelTypeKey)
{
var uniqueKey = templateKey.GetUniqueKeyString();
_cache.AddOrUpdate(uniqueKey, key =>
{
// new item added
_assemblies.Add(template.TemplateAssembly);
var dict = new ConcurrentDictionary<Type, ICompiledTemplate>();
dict.AddOrUpdate(modelTypeKey, template, (t, old) => {
throw new Exception("Expected the dictionary to be empty."); });
return dict;
}, (key, dict) =>
{
dict.AddOrUpdate(modelTypeKey, t =>
{
// new item added (template was not compiled with the given type).
_assemblies.Add(template.TemplateAssembly);
return template;
}, (t, old) =>
{
// item was already added before
return template;
});
return dict;
});
}
示例2: GetCompiledTemplate
/// <summary>
/// Tries to resolve the template.
/// When the cache misses we either throw an exception or compile the template.
/// Otherwise the result is returned.
/// </summary>
/// <param name="key"></param>
/// <param name="modelType"></param>
/// <param name="compileOnCacheMiss"></param>
/// <returns></returns>
internal ICompiledTemplate GetCompiledTemplate(ITemplateKey key, Type modelType, bool compileOnCacheMiss)
{
ICompiledTemplate template;
if (!_config.CachingProvider.TryRetrieveTemplate(key, modelType, out template))
{
if (compileOnCacheMiss)
{
template = CompileAndCacheInternal(key, modelType);
}
else
{
throw new InvalidOperationException("No template exists with key '" + key.GetUniqueKeyString() + "'");
}
}
return template;
}
示例3: TryRetrieveTemplate
/// <summary>
/// Try to retrieve a template from the cache. See <see cref="ICachingProvider.TryRetrieveTemplate"/>.
/// </summary>
/// <param name="templateKey"></param>
/// <param name="modelType"></param>
/// <param name="compiledTemplate"></param>
/// <returns></returns>
public bool TryRetrieveTemplate(ITemplateKey templateKey, Type modelType, out ICompiledTemplate compiledTemplate)
{
compiledTemplate = null;
var uniqueKey = templateKey.GetUniqueKeyString();
var modelTypeKey = GetModelTypeKey(modelType);
ConcurrentDictionary<Type, ICompiledTemplate> dict;
if (!_cache.TryGetValue(uniqueKey, out dict))
{
return false;
}
return dict.TryGetValue(modelTypeKey, out compiledTemplate);
}
示例4: InvalidateCacheOfType
/// <summary>
/// Invalidates the compilation of the given template with the given model-type.
/// WARNING: leads to memory leaks
/// </summary>
/// <param name="templateKey"></param>
/// <param name="modelType"></param>
public void InvalidateCacheOfType(ITemplateKey templateKey, Type modelType)
{
var uniqueKey = templateKey.GetUniqueKeyString();
var modelTypeKey = GetModelTypeKey(modelType);
ConcurrentDictionary<Type, ICompiledTemplate> dict;
if (!_cache.TryGetValue(uniqueKey, out dict))
{
// not cached
return;
}
ICompiledTemplate c;
dict.TryRemove(modelTypeKey, out c);
}
示例5: InvalidateCache
/// <summary>
/// Invalidates all compilations of the given template.
/// WARNING: leads to memory leaks
/// </summary>
/// <param name="templateKey"></param>
public void InvalidateCache(ITemplateKey templateKey)
{
var uniqueKey = templateKey.GetUniqueKeyString();
ConcurrentDictionary<Type, ICompiledTemplate> dict;
_cache.TryRemove(uniqueKey, out dict);
}