Typically, providers read configuration straight from the web.config by overriding the Initialize method of ProviderBase. In a typical domain class, I would look to inject this configuration via the constructor, but because we are using the ASP.NET provider model, the constructor must be empty. The GetCache method requires a cache name, so we need a mechanism to retreive this value from config. ![]() Instead, we use the GetCache method of the class. This class does not have a public constructor. In order for our provider to read and write to a Windows AppFabric Cache, we need to use the class which exposes all the methods we require. There are four abstract methods that we need to implement: Get, Add, Set and Remove. While AppFabric 1.0 comes with a DataCacheSessionStoreProvider for moving session state to AppFabric, an OutputCacheProvider implementation is not included so we will need to write our own. Replacing the built-in in-process output cache mechanism in ASP.NET is as simple as subclassing the abstract OutputCacheProvider class found in. Writing our initial AppFabricOutputCacheProvider We will discuss AppFabric 1.1 CTP later in the article but should you choose to download this preview version, you will find the DLLs in C:\Program Files\Windows Server AppFabric - 1.1 CTP. After installation, the DLLs can be found in C:\Windows\System32\AppFabric. I have included these in the code download later in the article but to get them yourself, download the AppFabric 1.0 installer and just install the "Cache Client". Having said that, in order to implement the provider we do need to reference some AppFabric DLLs. Scott Hanselman has a very good article covering the installation process should you need it. I am not going to cover the installation of Windows Server AppFabric because 1) it is outside the scope of this article, 2) many people have already written about it and 3) somebody from your infrastructure team has probably already installed a dev instance for you and given you the details :-). All web servers use the same cache data so all clients see the same data too. When an item can be removed from the cache, it is (effectively) removed for all web servers. ![]() You are not restricted to the memory on each web server. ![]() Unlike in-process caching, AppFabric caches are not lost when your IIS app pool recycles. This allows all web servers in your web farm to share a single (distributed) cache. Instead of caching items in memory on the web server, AppFabric allows you to distribute your items across multiple cache hosts. Why use Windows Server AppFabric Caching? We will also discuss a big limitation with the MVC3 OutputCacheAttribute and explain how this is addressed by the MvcDonutCaching NuGet package. This post explains how to create an AppFabric OutputCacheProvider and how to configure ASP.NET to use the new provider. Thanks to the extensibility features introduced with ASP.NET 4.0, modifying an application to use a distributed cache is a very simple process. ASP.NET MVC Output Caching with Windows AppFabric CacheĮnterprise level web applications are typically hosted in web farms where in-process caching is less useful than a distributed caching approach such as Windows Server AppFabric or Memcached.
0 Comments
Leave a Reply. |