当前位置: 首页>>代码示例>>C#>>正文


C# ITemplateKey.GetUniqueKeyString方法代码示例

本文整理汇总了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;
     });
 }
开发者ID:MatthewSJones,项目名称:RazorEngine,代码行数:26,代码来源:InvalidatingCachingProvider.cs

示例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;
        }
开发者ID:lijianguang,项目名称:RazorEngine,代码行数:26,代码来源:RazorEngineService.cs

示例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);
 }
开发者ID:rmeshksar,项目名称:RazorEngine,代码行数:19,代码来源:DefaultCachingProvider.cs

示例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);
 }
开发者ID:RoboBurned,项目名称:RazorEngine,代码行数:19,代码来源:InvalidatingCachingProvider.cs

示例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);
 }
开发者ID:RoboBurned,项目名称:RazorEngine,代码行数:11,代码来源:InvalidatingCachingProvider.cs


注:本文中的ITemplateKey.GetUniqueKeyString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。