Can AppFabric be the session state provider and use local cache?

I am using AppFabric as the session state provider in my ASP.Net MVC2 app, and I would like it to also use the local cache. 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 the 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 session then run the following two commands in the AppFabric powershell, anything I added to my session data is no longer there which leaves me to believe it was not using local cache:

Stop-CacheCluster
Start-CacheCluster

I also try caching objects with AppFabric using the following code and after I start and stop the CacheCluster the once cached object is no longer cached:

var factory = new DataCacheFactory();
var cache = factory.GetCache("Default");
cache.Put("Key", "Test");

However if I instantiate AppFabric using the following code where I explicitly tell it to use 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 doesn't my web.config entry work in telling AppFabric to use local cache? Can you use AppFabric as your session state provider and also have it use local cache?

6
задан PhilPursglove 12 September 2010 в 20:26
поделиться