5

I'm currently trying to create a class library and embed the MVC views in it so we can share it across multiple sites as explained here: http://www.wynia.org/wordpress/2008/12/aspnet-mvc-plugins/

Performance is important so I'm trying to figure out if this is the way to go. Could someone explain VirtualPathProvider somewhat briefly if possible?

I've noticed that this method is only called once for each file.

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

    return base.GetFile(virtualPath);
}

Does the VirtualPathProvider caches the file/view automatically? In another article (explaining the same thing) they stated you should override the 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);
}

So returning null here doesn't affect the "caching" of the VirtualFile? The reason I'm asking this is because the custom implementation of VirtualFile we created, called EmbeddedVirtualFile, uses this piece of code in the overridden Open()-method:

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

I'm somewhat afraid this will have a performance hit. Can someone reassure me?

thomasvdb
  • 739
  • 1
  • 11
  • 32

0 Answers0