存储在会话中的值取决于 HttpRuntime 缓存中的值
我将所有用户通用的数据存储在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
缓存依赖性以另一种方式工作,即当缓存依赖于其他东西时,而不是当某些东西依赖于缓存时。
无法使用
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 theSession
object is not possible. The callback is not called in the scope of a specific user, so you can't access theSession
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.