0

I am building a cms System which depend on VirtualPathProvider. I need to show the cashed page with ability to release this cache. here is the code where the cache is built. how can I access to this cache? to show a list of cached pages

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);
}
Kjensen
  • 12,447
  • 36
  • 109
  • 171
Bakri
  • 597
  • 10
  • 22

1 Answers1

1

The Problem has been solved by creating CustomeCacheDependency

 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();
        }
    }
}
Bakri
  • 597
  • 10
  • 22