【问题标题】:How to clear whole Windows Azure Appfabric Cache on WebRole start?如何在 WebRole 启动时清除整个 Windows Azure Appfabric 缓存?
【发布时间】:2011-12-27 06:57:28
【问题描述】:

我正在尝试做一件简单的事情,但我找不到答案。 我知道如何在应用程序级别(对于网站)删除缓存。

但我需要在 webrole 启动时清除我的 azure appfabric 缓存的所有缓存。

编辑:如果可以做到呢?考虑到 Azure Asp.net 共享缓存中的严重故障,还是我很笨?

这是我陷入的场景:

  • 我有一个 WebRole,其中有几个不同的网站
  • 考虑到我所有的网站在每个根目录都有一个 default.aspx 文件,缓存时间为 60 分钟,这是普通的常规 ,没有花哨的代码
  • 我浏览它们,因此几个缓存页面在 appfabric 缓存中存储了 60 分钟
  • 请考虑在此部署缓存依赖项的底层是在“E:\sitesroot\xx”之类的路径上创建的
  • 在此期间,我的 Webrole 重置或我上传新部署
  • 现在考虑我的网站在新创建的实例中具有以下路径:'F:\sitesroot\xx'
  • 你明白了,这是我得到的结果:

目录“E:\sitesroot\12”不存在。无法开始监控文件更改。

System.Web.HttpException (0x80070003): Directory 'E:\sitesroot\12' does not exist. Failed to start monitoring file changes.
at System.Web.FileChangesMonitor.FindDirectoryMonitor(String dir, Boolean addIfNotFound, Boolean throwOnError)
at System.Web.FileChangesMonitor.StartMonitoringPath(String alias, FileChangeEventHandler callback, FileAttributesData& fad)
at System.Web.Caching.CacheDependency.Init(Boolean isPublic, String[] filenamesArg, String[] cachekeysArg, CacheDependency dependency, DateTime utcStart)
at System.Web.Caching.CacheDependency..ctor(Int32 dummy, String[] filenames)
at System.Web.Caching.OutputCache.HasDependencyChanged(Boolean isFragment, String depKey, String[] fileDeps, String kernelKey, String oceKey, String providerName)
 at System.Web.Caching.OutputCache.Get(String key)
 at System.Web.Caching.OutputCacheModule.OnEnter(Object source, EventArgs eventArgs)
at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
 at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)

我花了一些时间才明白这个问题可能是因为当前的 appfacbric 缓存依赖于硬路径“E:\sitesroot\”的缓存依赖。如果这条路径改变了怎么办?

那我该怎么办?我迷路了,我试图清除 Global.asax Application_Start 上的 appcache,但这似乎不起作用(我不明白为什么它不起作用)。

这是我清除每个网站 Global.asax Application_Start 缓存的代码

Public Shared Sub cacheClear()

    Dim keys As New List(Of String)()
    ' retrieve application Cache enumerator
    Dim enumerator As IDictionaryEnumerator = HttpRuntime.Cache.GetEnumerator()
    ' copy all keys that currently exist in Cache
    While enumerator.MoveNext()
        keys.Add(enumerator.Key.ToString())
    End While
    ' delete every key from cache
    For i As Integer = 0 To keys.Count - 1
        HttpRuntime.Cache.Remove(keys(i))
    Next

End Sub

这应该可以解决问题,但似乎没有。

我肯定错过了一个荒谬的观点。

编辑

我结束了完全放弃 appfabric 的 asp.net 输出缓存提供程序并使用 appfabric 编写自定义缓存。效果很好,几行代码和对 azure 的缓存依赖变得容易。

【问题讨论】:

    标签: azure appfabric azure-caching


    【解决方案1】:

    我不是 100% 确定,但我不认为这可以做到。

    【讨论】:

    • 嗨,我想我在 Azure“即插即用”Asp.net 缓存系统中发现了一个严重的错误逻辑,我会更新我的帖子。
    猜你喜欢
    • 2011-08-17
    • 1970-01-01
    • 2015-04-16
    • 2011-12-24
    • 2012-11-22
    • 2016-09-10
    • 2016-12-17
    • 1970-01-01
    • 2014-03-02
    相关资源
    最近更新 更多