I use AppFabric as the session state provider in my ASP.Net MVC2 application, and I would like it to use the local cache as well. I have the following entry in my web.config right after the configSections node:
<dataCacheClient> <localCache isEnabled="true" sync="TimeoutBased" objectCount="100000" ttlValue="300" /> <hosts> <host name="127.0.0.1" cachePort="22233"/> </hosts> </dataCacheClient>
I also have the following entry in web.config as a child of system.web node:
<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider"> <providers> <add name="AppFabricCacheSessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider" cacheName="Default" sharedId="DefaultId"/> </providers> </sessionState>
Unfortunately, if I add something to the session, run the following two commands in the PowerShell AppFabric, all that I added to my session data no longer exists, which leaves me to believe that it does not use the local cache:
Stop-CacheCluster Start-CacheCluster
I also try to cache objects using AppFabric using the following code, and after I started and stopped CacheCluster, the cached object stops caching:
var factory = new DataCacheFactory(); var cache = factory.GetCache("Default"); cache.Put("Key", "Test");
However, if I create an instance of AppFabric using the following code, where I explicitly tell it to use the local cache, rather than relying on the web.config entry, it works:
var servers = new List<DataCacheServerEndpoint>(1) { new DataCacheServerEndpoint("127.0.0.1", 22233) }; var configuration = new DataCacheFactoryConfiguration { Servers = servers, LocalCacheProperties = new DataCacheLocalCacheProperties(100000, new TimeSpan(0, 30, 0), DataCacheLocalCacheInvalidationPolicy.TimeoutBased) }; var factory = new DataCacheFactory(configuration); var cache factory.GetCache("StpWebSession"); cache.Put("Key", "Test");
What am I doing wrong, why does my entry in web.config not say that AppFabric uses the local cache? Can you use AppFabric as a session state provider and also use the local cache?