当用户会话持有基于该 DataTable 的 DataView 时处理对缓存 DataTable 的更新

发布于 2024-07-08 20:11:11 字数 161 浏览 4 评论 0原文

我的网站在一台服务器上运行。 我正在缓存一个数据表。 每个会话都有对其自己的 DataView 的引用,而 DataView 又引用该 DataTable。 我担心的是,当我需要对底层数据表进行更改时,它们是否会传播到对其的每个会话引用。

或者有没有更好的方法来处理这种情况。

My website runs on a single server. I am caching a DataTable. Each session has a refernce to it's own DataView referring to that DataTable. What I am worried about is when I need to make changes to the underlying datatable will they propagate to each of the sessions references to it.

Or is there a better way to handle this situation.

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

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

发布评论

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

评论(1

橘虞初梦 2024-07-15 20:11:11

原则上是的。 如果您继续使用相同的数据表,更改将传播到视图。 但是,根据您的实现方式,可能会出现问题:

  • 首次生成缓存的 DataTable 时存在潜在的竞争条件:对服务器的多个请求可能会检测到缓存的 DataTable 不存在,并尝试生成它 - 在这种情况下,您可能有一个重复的数据表。

  • 缓存的 DataTable(例如,如果由于超时到期而将其从 ASP.NET 缓存中删除),则 Session 中的现有 DataView 将继续引用旧的 DataTable。

In principle, yes. Changes will propagate to views provided you continue to use the same DataTable. However there is a potential for problems depending on how you implement this:

  • You have a potential race condition when generating the cached DataTable for the first time: multiple requests to the server may detect that the cached DataTable does not exist, and attempt to generate it - in this case you could have a duplicate DataTable.

  • If you regenerate the cached DataTable (for example if it is removed from the ASP.NET cache due to a timeout expiring), then existing DataViews in Session will continue to reference the old DataTable.

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