I am doing some dev work using portable areas so I have an overridden VirtualPathProvider
.
My public override bool FileExists(string virtualPath)
seems to get called only every few minutes, meaning that MVC is caching the views.
This is probably great in production but I can't figure out how to turn it off in dev. I want the VirtualPathProvider
to get called on each and every use of the view.
Any suggestions?
Answering my own question for the sake of future generations....
We ended up overriding the GetCacheDependency call to ensure that the view is never cached. (We cache views manually). We had to create a FakeCacheDependency that lets us use the last modified date from our cache.
In our application, our virtual views are called CondorVirtualFiles. (When building a views engine, you need to give it a cool name.)
public override System.Web.Caching.CacheDependency GetCacheDependency(string virtualPath, System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
{
var view = this.GetFile(virtualPath);
if (view is CondorVirtualFile)
{
FakeCacheDependency fcd = new FakeCacheDependency((view as CondorVirtualFile).LastModified);
return fcd;
}
return base.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
public class FakeCacheDependency : System.Web.Caching.CacheDependency
{
public FakeCacheDependency(DateTime lastModified)
{
base.SetUtcLastModified(lastModified);
}
public FakeCacheDependency()
{
base.SetUtcLastModified(DateTime.UtcNow);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With