VirtualPathProvider性能

tho*_*vdb 5 c# asp.net-mvc virtualpathprovider

我目前正在尝试创建一个类库并将MVC视图嵌入其中,以便我们可以在多个站点上共享它,如下所述:http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins /

性能很重要,所以我想弄清楚这是否可行.如果可能的话,有人可以稍微解释一下VirtualPathProvider吗?

我注意到这个方法只为每个文件调用一次.

public override VirtualFile GetFile(string virtualPath)
{
    if (ResourceFileExists(virtualPath))
         return new EmbeddedVirtualFile(virtualPath);

    return base.GetFile(virtualPath);
}
Run Code Online (Sandbox Code Playgroud)

VirtualPathProvider是否自动缓存文件/视图?在另一篇文章中(解释相同的事情),他们声明你应该覆盖GetCacheDependency:

public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
{
    if (ResourceFileExists(virtualPath))
        // Return null or otherwise ASP.NET will try to monitor the file.
        // Is actually the default implementation.
        return null;

    return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
Run Code Online (Sandbox Code Playgroud)

所以在这里返回null不会影响VirtualFile的"缓存"?我问这个的原因是因为我们创建的VirtualFile的自定义实现,称为EmbeddedVirtualFile,在重写的Open()方法中使用了这段代码:

var assembly = Assembly.LoadFile(assemblyName);
if (assembly != null)
{
    Stream resourceStream = assembly.GetManifestResourceStream(resourceName);
    return resourceStream;
}
Run Code Online (Sandbox Code Playgroud)

我有点害怕这会有性能损失.有人可以安慰我吗?