kdstack
kdstack

Reputation: 197

How to clear whole Windows Azure Appfabric Cache on WebRole start?

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 :

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.

Upvotes: 4

Views: 1191

Answers (1)

user94559
user94559

Reputation: 60153

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

Upvotes: 1

Related Questions