I'm having a bit performance problem here: the code below is part from my custom VirtualPathProvider, I've overwritten the GetCacheKey, and GetCacheDependency so they can cache my razor views properly.
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;
}
}
However currently I'm a bit concerned whether my code is correct or not - because when I test it on my local PC, it works perfectly, however if I upload it to Azure websites, it takes AGES to get the pages rendered.
The views are stored on Azure Blob storage, and I put log entries on the GetFile and find they are cached, however it does look like the website is getting constantly recompiled on each page (yes each page, because when it is compiled if I refresh the Azure website page it gets displayed instantly, but not other pages that I haven't visited)
So my first guess is - Azure website performance is very poor, however then I upgraded it to P3 Large Instance Web App Service Plan and got still the same problem. So it made me thinking do I have any error the in VirtualPathProvider again? As GetFile() method is not always hit and the visited page gets displayed immediate after refresh, I'm sure the caching is also working, so it leaves me thinking whether there's any other compilation happening during the process that causes each page taking so much time for the first load?
Can anyone help please...
Thanks in advance.