首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >操纵VirtualPathProvider缓存

操纵VirtualPathProvider缓存
EN

Stack Overflow用户
提问于 2015-02-02 08:30:04
回答 1查看 413关注 0票数 0

我正在构建一个基于VirtualPathProvider的cms系统。我需要显示有能力释放这个缓存的已兑现的页面。以下是构建缓存的代码。我如何访问这个缓存?若要显示缓存页列表,请执行以下操作

代码语言:javascript
复制
public override CacheDependency GetCacheDependency(
string virtualPath, 
System.Collections.IEnumerable virtualPathDependencies, 
DateTime utcStart)
{
  if (IsPathVirtual(virtualPath))
  {
System.Collections.Specialized.StringCollection fullPathDependencies = null;

// Get the full path to all dependencies. 
foreach (string virtualDependency in virtualPathDependencies)
{
  if (fullPathDependencies == null)
    fullPathDependencies = new System.Collections.Specialized.StringCollection();

  fullPathDependencies.Add(virtualDependency);
}
if (fullPathDependencies == null)
  return null;

// Copy the list of full-path dependencies into an array. 
string[] fullPathDependenciesArray = new string[fullPathDependencies.Count];
fullPathDependencies.CopyTo(fullPathDependenciesArray, 0);
// Copy the virtual path into an array. 
string[] virtualPathArray = new string[1];
virtualPathArray[0] = virtualPath;

return new CacheDependency(virtualPathArray, fullPathDependenciesArray, utcStart);
}
else 
return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-04-24 07:47:29

这个问题已经通过创建CustomeCacheDependency解决了

代码语言:javascript
复制
 public override CacheDependency GetCacheDependency(string virtualPath,
        System.Collections.IEnumerable virtualPathDependencies, DateTime utcStart)
    {
         if (IsPathVirtual(virtualPath))
             {
                  return CashManager.SetPageCash(virtualPath);
             }
        return Previous.GetCacheDependency(virtualPath, virtualPathDependencies, utcStart);
    }



public class SecuHostCacheDependency: System.Web.Caching.CacheDependency
{
    public CustomeCacheDependency()
    {
        base.SetUtcLastModified(DateTime.UtcNow);
    }
    public void Clear()
    {
         base.SetUtcLastModified(DateTime.UtcNow);
        NotifyDependencyChanged(this, EventArgs.Empty);
    }
}

public class CashManager
{
    // Page Cash
    public static CustomeCacheDependency SetPageCash(string url)
    {
       CustomeCacheDependency customeCacheDependency = new CustomeCacheDependency ();
 System.Web.HttpContext.Current.Application[url]=customeCacheDependency;


        return customeCacheDependency;
    }
    public static void ClearPageCash(string url)
    {
        CustomeCacheDependency  customeCacheDependency=
   System.Web.HttpContext.Current.Application[url] as customeCacheDependency;
        if (CustomeCacheDependency != null)
        {
          CustomeCacheDependency.Clear();
        }
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/28273673

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档