static void Main(string[] args)
{
string cshtml = File.ReadAllText(@"E:百度云同步盘StudyNet_ASP.NETWeb基本原理RazorCacheNameTestHTMLPage1.cshtml");
for (int i = 0; i < 1000; i++)
{
string html = Razor.Parse(cshtml);
}
Assembly[] asms = AppDomain.CurrentDomain.GetAssemblies();
foreach (Assembly asm in asms)
{
Console.WriteLine(asm.FullName+"rn");
}
Console.ReadKey();
}
for (int i = 0; i < 1000; i++)
{
//如果调用1000次,使用下面方式就会创建很多程序集,性能很低
string html = Razor.Parse(cshtml);
//解析的cshtml文件我给的一个“缓存名”是cc,这次一旦编译成功
//下次再让你Parse() cc就不用重复编译了,速度会非常快,
//除非cshtml内容修改
Razor.Parse(cshtml, null, "cc");
}
for (int i = 0; i < 10; i++)
{
string cshtml = File.ReadAllText(fullPath);
string cacheName = fullPath + File.GetLastWriteTime(fullPath);
//文件全路径+文件上一次被修改时间
string html = Razor.Parse(cshtml,null,cacheName);
Console.WriteLine(html);
Console.ReadKey();
}
private ITemplate GetTemplate<T>(string razorTemplate, object model, string cacheName)
{
Func<string, CachedTemplateItem, CachedTemplateItem> updateValueFactory = null;
CachedTemplateItem item;
if (razorTemplate == null)
{
throw new ArgumentNullException("razorTemplate");
}
int hashCode = razorTemplate.GetHashCode();
if (!this._cache.TryGetValue(cacheName, out item) || (item.CachedHashCode != hashCode))
{
Type templateType = this.CreateTemplateType(razorTemplate, (model == null) ? typeof(T) : model.GetType());
item = new CachedTemplateItem(hashCode, templateType);
if (updateValueFactory == null)
{
updateValueFactory = (n, i) => item;
}
this._cache.AddOrUpdate(cacheName, item, updateValueFactory);
}
return this.CreateTemplate(null, item.TemplateType, model);
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有