I am trying to do something that may be simple, but I just cannot find the answer. I know how to remove cache at the application level (for a website).
But I need to READ ALL QUALITY of my azure appfabric cache when starting webrole.
EDIT: What if it can be done? Given a serious caching issue in Azure Asp.net or am I dumb?
This is the scenario I'm stuck in:
- I have a WebRole that has several different sites.
- All my sites have a default.aspx file for each root with 60 minutes of caching, this is a regular regular <% @OutputCache Duration = "3600" VaryByParam = "*"%>, not fancy code
- I look through them, so several cached pages are stored in cache folders for 60 minutes.
- Consider that an uner hood in this deployment deployment cache is created along a path similar to "E: \ sitesroot \ xx"
- In between, my webrole reset or I load a new deployment
- Now consider that my sites in newly created instances have this path: 'F: \ sitesroot \ xx'
- You will get this, here is the result:
The 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 several times to understand that this question MAY BE, because the current appfacbric cache relied on cachedepency with the hard path "E: \ sitesroot". What to do if this path changes, if any.
So what can I do? I got lost here, I tried to clean the appcache from Global.asax Application_Start, but this does not seem to work (and I do not understand why this is not).
Here is my code to clear the cache on every Global.asax Application_Start website
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
That should do the trick, it doesn't look like.
There, of course, is a ridiculous moment that I miss.
EDIT
I ended up completely dropping the asp.net outputcache provider for appfabric and writing my own cache with appfabric. Works great, a few lines of code and the interdependence on azure have become easy.