如何清除 WebRole 启动时的整个 Windows Azure Appfabric 缓存?

发布于 2024-12-15 05:02:27 字数 2632 浏览 2 评论 0原文

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

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

编辑:如果可以做到怎么办? 到 Azure Asp.net 共享缓存中的严重故障还是我很

愚蠢

  • 考虑
  • ?每个根都有 60 分钟的缓存,这是普通的常规 <%@ OutputCache Duration="3600" VaryByParam="*" %>,没有花哨的代码
  • 我浏览它们,因此有几个缓存页面存储在 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 上的应用程序缓存,但这似乎不起作用(而且我不明白为什么它不起作用)。

这是我的代码,用于清除每个网站上的缓存 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 的缓存依赖变得很容易。

I'm trying to do what might be a simple thing, but i just can't find the answer.
I know how to delete cache on the application level (for a website).

But i need to CLEAR ALL THE CACHE of my azure appfabric cache on webrole start.

EDIT : What if it can be done ? Considering a severe misfunction in Azure Asp.net shared caching or am I dumb ?

This this the scenario i'm stuck into :

  • I have a a WebRole which have few different websites
  • Consider all my websites have a default.aspx file on each root with a 60 minutes caching, this is plain regular <%@ OutputCache Duration="3600" VaryByParam="*" %>, no fancy code
  • I browse them, consequently several cached pages are stored in appfabric caches for 60 minutes
  • Consider uner the hood in this deployment cache depencies are created upon a path like 'E:\sitesroot\xx'
  • In between, my Webrole reset or I upload a new deployment
  • Now consider my websites in newly created instances have this path : 'F:\sitesroot\xx'
  • You get it, heres the result I have :

Directory 'E:\sitesroot\12' does not exist. Failed to start monitoring file changes.

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)

It took me some times to understand that this issue MIGHT BE because the current appfacbric cache relied on a cachedepency with a hard path "E:\sitesroot\". What if this path change, has it DOES.

So what can I do ? I'm lost here, I tried to clear appcache on Global.asax Application_Start, but this does not seem to work (and i don't understand why it does not).

Here's my code to clear cache on each websites 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

This should do the trick, it does not seems to.

There certainly a ridiculous point i'm missing.

EDIT

I ended dropping completely asp.net outputcache provider for appfabric and writing a custom cache with appfabric. Works great, few line of codes and cachedependancy on azure made easy.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

执着的年纪 2024-12-22 05:02:27

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

I'm not 100% sure, but I don't think this can be done.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文