我在这里遇到了一点性能问题:下面的代码是我的自定义 VirtualPathProvider 的一部分,我已经覆盖了 GetCacheKey 和 GetCacheDependency,因此它们可以正确地缓存我的剃刀视图。
public override string GetCacheKey(string virtualPath)
{
var key = string.Empty;
var fileResult = VerifyFilePath(virtualPath);
if (fileResult.RefinedAccessPath.IsNotNullOrEmpty())
key = EncryptHelper.MD5Encrypt(fileResult.RefinedAccessPath);
else
key = EncryptHelper.MD5Encrypt(fileResult.VirtualPath);
return key;
}
public override string GetFileHash(string virtualPath, System.Collections.IEnumerable virtualPathDependencies)
{
var fileResult = VerifyFilePath(virtualPath);
var hash = string.Empty;
if (fileResult.RefinedAccessPath.IsNotNullOrEmpty())
hash = EncryptHelper.MD5Encrypt(fileResult.RefinedAccessPath);
else
hash = Previous.GetFileHash(fileResult.VirtualPath, virtualPathDependencies);
return hash;
}
public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
{
var fileResult = VerifyFilePath(virtualPath);
switch (fileResult.Result)
{
case ExistenceResult.FoundInCloudAfterRebuildPath:
case ExistenceResult.FoundInCloudDirectly:
return new OSiteCacheDependency(fileResult.LastModified, ositeVirtualPathHelper.SiteID.ToString(), utcStart);
default:
if (fileResult.RefinedAccessPath.IsNotNullOrEmpty())
return new System.Web.Caching.CacheDependency(fileResult.RefinedAccessPath);
else
return null;
}
}
但是目前我有点担心我的代码是否正确 - 因为当我在本地 PC 上测试它时,它可以完美运行,但是如果我将它上传到 Azure 网站,则需要 AGES 才能渲染页面。
视图存储在 Azure Blob 存储中,我将日志条目放在 GetFile 上并发现它们被缓存,但是看起来网站在每个页面上都在不断重新编译(是的,每个页面,因为当我刷新时它被编译Azure 网站页面会立即显示,但不会显示我未访问过的其他页面)
所以我的第一个猜测是 - Azure 网站性能很差,但后来我将它升级到 P3 大型实例 Web 应用服务计划,仍然遇到同样的问题。所以这让我想我在 VirtualPathProvider 中是否有任何错误?由于 GetFile() 方法并不总是被命中并且访问的页面在刷新后立即显示,我确信缓存也在工作,所以它让我思考在这个过程中是否发生了任何其他编译导致每个页面占用这么多第一次加载的时间?
谁能帮忙请...
提前致谢。