从命令行或Powershell脚本删除ARR缓存中的所有缓存对象 [英] Delete All Cached Objects in ARR Cache from Command Line or Powershell Script

查看:133
本文介绍了从命令行或Powershell脚本删除ARR缓存中的所有缓存对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档描述了如何使用IIS管理器的应用程序请求路由缓存小程序删除所有缓存的对象(详细信息在这里: http://learn.iis.net/page.aspx/576/delete-cached-objects/ )。

Documentation describes how to delete all cached objects using the IIS Manager's Application Request Routing Cache applet (details here: http://learn.iis.net/page.aspx/576/delete-cached-objects/). How might this be done from the command line or powershell script?

在我的情况下,我确实具有本地磁盘缓存,并且删除该文件夹中的文件不会导致要重新计算的文件。

In my case I do have a local disk cache and deleting the files in that folder doesn't cause the files to be re-calculated. What else is required?

推荐答案

下面的C#代码示例是一个简单的控制台程序,可以删除缓存的所有内容,或者从缓存中删除您要清除的特定URL。

The following C# code sample is a simple console program that can delete all contents of the cache, or delete a specific URL that you wish to clear from the cache.

要对此进行编译,您需要引用我在GAC中找到的 Microsoft.Web.Administration DLL(尽管

In order for this to compile, you will need to reference the Microsoft.Web.Administration DLL which I found in the GAC (though I also believe it is part of the Windows SDK as well).

using Microsoft.Web.Administration;
using System;

namespace IISCacheManager
{
  class Program
  {
    static void Main(string[] args)
    {
      if (args.Length != 1)
      {
        Console.WriteLine("Incorrect Usage: Specify the URL that you want to flush the cache for. To delete everything, specify 'ALL'.");
        Environment.Exit(1);
      }

      var url = args[0] == "ALL" ? string.Empty : args[0];

      var m = new ServerManager();
      var x = m.GetApplicationHostConfiguration().GetSection("system.webServer/diskCache");
      var method = x.Methods["FlushUrl"].CreateInstance();
      method.Input.SetAttributeValue("url", url);
      method.Execute();
      Console.WriteLine("Item flushed successfully.");
    }
  }
}

希望这会有所帮助!

这篇关于从命令行或Powershell脚本删除ARR缓存中的所有缓存对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆