Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VirtualPathProvider performance [duplicate]

I have a virtual path provider. Problem is its caching my files. Whenever I manually edit one of the aspx files it references the VPP doesn't pull in the new file, it continues to reuse the old file until I restart the site.

I've even over-rode the GetCacheDependency() in my VirtualPathProvider class:

    public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
    {
        return null;
    }

Ideas?

like image 698
downatone Avatar asked Nov 24 '22 19:11

downatone


1 Answers

Returning a null is essentially telling ASP.NET that you do not have any dependency - hence ASP.NET will not reload the item.

What you need is to return a valid dependency e.g.

 public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
    {
        return new CacheDependency(getPhysicalFileName(virtualPath));
    }

A more correct approach is to make sure that you only handle your own cache dependencies (this is a schematic example) :

 public override CacheDependency GetCacheDependency(string virtualPath, IEnumerable virtualPathDependencies, DateTime utcStart)
    {
        if (isMyVirtualPath(virtualPath))
            return new CacheDependency(getPhysicalFileName(virtualPath));
        else
            return new Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
    }
like image 123
Samir Seth Avatar answered Mar 17 '23 03:03

Samir Seth