存储在会话中的值取决于 HttpRuntime 缓存中的值

发布于 2024-11-27 23:56:46 字数 302 浏览 5 评论 0原文

我将所有用户通用的数据存储在 HttpRuntime.Cache 中。

然后我在 Session 中存储了一些与用户相关的数据。

HttpRuntime.Cache具有CacheDependency机制,可用于定义缓存中项目之间的关系。

您将使用什么来处理会话和运行时缓存之间的依赖关系?

除了 CacheDependency 之外,还有 CacheItemRemovedCallback。如果可能的话,我可以在此回调期间从每个会话中删除特定值。

I have data common for all users stored in HttpRuntime.Cache.

Then I have some user related data stored in Session.

HttpRuntime.Cache has CacheDependency mechanism, which can be used to define relationships between the items in cache.

What would you use to handle the dependency between Session and Runtime Cache?

Additional to CacheDependencies, there is also CacheItemRemovedCallback. I could remove specific values from each session during this callback, if it's even possible.

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

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

发布评论

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

评论(1

GRAY°灰色天空 2024-12-04 23:56:46

缓存依赖性以另一种方式工作,即当缓存依赖于其他东西时,而不是当某些东西依赖于缓存时。

无法使用 CacheItemRemovedCallback 更新 Session 对象中的项目。该回调不会在特定用户的范围内调用,因此您无法访问 Session 对象。您必须将数据保存在其他地方,以便您可以访问所有用户的数据,因为取决于从缓存中删除的项目的数据可能属于任何用户。

The cache dependency works the other way, i.e. when the cache is dependent on something else, not when something is dependent on the cache.

Using the CacheItemRemovedCallback to update items in the Session object is not possible. The callback is not called in the scope of a specific user, so you can't access the Session object. You would have to keep the data somewhere else, so that you can access the data for all users, as the data depending on the item removed from the cache may belong to any user.

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