gpt4 book ai didi

c# - 虚拟路径提供程序禁用缓存?

转载 作者:太空狗 更新时间:2023-10-29 23:52:13 25 4
gpt4 key购买 nike

我有一个虚拟路径提供程序。问题是它缓存我的文件。每当我手动编辑它引用的其中一个 aspx 文件时,VPP 不会引入新文件,它会继续重复使用旧文件,直到我重新启动站点。

我什至在我的 VirtualPathProvider 类中覆盖了 GetCacheDependency():

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

想法?

最佳答案

返回 null 实质上是告诉 ASP.NET 您没有任何依赖项 - 因此 ASP.NET 不会重新加载该项目。

你需要的是返回一个有效的依赖,例如

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

更正确的做法是确保只处理自己的缓存依赖项(这是一个示意图示例):

 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);
}

关于c# - 虚拟路径提供程序禁用缓存?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11643863/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com