AppFabric 可以作为会话状态提供者并使用本地缓存吗?

发布于 2024-09-18 08:08:45 字数 1865 浏览 4 评论 0原文

我在 ASP.Net MVC2 应用程序中使用 AppFabric 作为会话状态提供程序,并且我希望它也使用本地缓存。我的 web.config 中的 configSections 节点后面有以下条目:

<dataCacheClient>
    <localCache
         isEnabled="true"
         sync="TimeoutBased"
         objectCount="100000"
         ttlValue="300" />
    <hosts>
        <host name="127.0.0.1" cachePort="22233"/>
    </hosts>
</dataCacheClient>

我在 web.config 中也有以下条目作为 system.web 节点的子节点:

<sessionState mode="Custom" customProvider="AppFabricCacheSessionStoreProvider">
    <providers>
        <add name="AppFabricCacheSessionStoreProvider" type="Microsoft.ApplicationServer.Caching.DataCacheSessionStoreProvider" cacheName="Default" sharedId="DefaultId"/>
    </providers>
</sessionState>

不幸的是,如果我向会话添加某些内容,则在中运行以下两个命令AppFabric powershell,我添加到会话数据中的任何内容都不再存在,这让我相信它没有使用本地缓存:

Stop-CacheCluster
Start-CacheCluster

我还尝试使用以下代码使用 AppFabric 缓存对象,并在启动和停止 CacheCluster 后缓存一次对象不再缓存:

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

但是,如果我使用以下代码实例化 AppFabric,并明确告诉它使用本地缓存而不是依赖 web.config 条目,它会起作用:

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");

我做错了什么,为什么我的 web.config 条目没有告诉 AppFabric 使用本地缓存?您可以使用 AppFabric 作为会话状态提供程序并让它使用本地缓存吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

冷了相思 2024-09-25 08:08:45

我在 发现了一些小曲http://social.msdn.microsoft.com/Forums/en-US/velocity/thread/24e72dab-bb20-47ec-aae2-77423b1d296b

基本上,“enableSessionState”默认为“true”,这意味着您需要远程处理所有请求。如果将该属性设置为“ReadOnly”,将从本地缓存中检索会话状态对象。然后,如果本地缓存失效,它将再次转到远程存储。

I found a little ditty at http://social.msdn.microsoft.com/Forums/en-US/velocity/thread/24e72dab-bb20-47ec-aae2-77423b1d296b.

Basically, "enableSessionState" is "true" by default meaning you need to go remote for all requests. If you set the property to "ReadOnly" the session state object will be retrieved from the Local Cache. Then if local cache is invalidated it will go to remote store again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文