在 Silverlight 中维护数据库对象内存缓存的最佳方法

发布于 2024-10-16 18:58:45 字数 354 浏览 5 评论 0原文

我想在 silverlight 的内存中设置数据库对象(即表中的行)的缓存,我将使用 WCF 和 linq-to-sql 来完成此操作。一旦我将对象放入内存中,我就计划使用 MSMQ 在新对象被修改时接收它们。这是一种有点复杂的方法,但目标是减少数据库访问并允许连接到 MSMQ 的 Silverlight 应用程序之间进行即时数据通信。

我的 Silverlight 应用程序需要长时间运行,并且要缓存的数据量不会很大。我计划使用本地存储来保存内存缓存。

无论如何,为了处理传入的更新对象,我想知道用户是否更改了现有对象。我可以使用一些与数据绑定相关的事件来设置一个标志来指示对象已更改吗?

也许有更好的方法来完全缓存?

谢谢!

I'd like to set up a cache of database objects (i.e. rows in a table) in memory in silverlight, which I'll do using WCF and linq-to-sql. Once I have the objects in memory, I'm planning on using MSMQ to receive new objects whenever they have been modified. It's a somewhat complex approach but the goal is to reduce trips to the database and allow instant data communication between Silverlight applications that are connected to the MSMQ.

My Silverlight applications are meant to be long-running and the amount of data to be cached will not be large. I'm planning on saving the in-memory cache using local storage.

Anyway, in order to process the updated objects that come in, I'd like to know if the user has changed the existing object. Could I use some event relating to data-binding to set a flag indicating that the object has changes?

Maybe there's a better way to do the cache entirely?

Thanks!

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

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

发布评论

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

评论(2

酷炫老祖宗 2024-10-23 18:58:45

我认为需要更多澄清才能理解您的要求。有些话你说的不清楚,甚至是矛盾的。但是,有一些一般性的想法:

  1. 如果缓存中的数据量不大,我就不会费心使用本地存储——我只会将其存储在某些应用程序级范围(全局变量、应用程序上下文、 ETC。)。如果应用程序重新启动,则必须从数据库中重新提取缓存(我想无论如何这都是可取的)。

  2. 通常,缓存的对象是只读的(用户无法更改)。如果用户确实更改了要缓存的对象,您通常希望立即将该信息保留到服务器/数据库,以便其他客户端可以获得该信息。

  3. 如果服务器/数据库保存“主”缓存数据,并且需要在数据更改时通知客户端,则 silverlight 应用程序可能必须成为某种服务的订阅侦听器(MSMQ 实际上可能作为后端)。如果更新不必是实时的,请考虑缓存只需在计时器上刷新一次,大约每 5-10 分钟左右。

I think a little more clarification is needed to understand your requirements. Some things you say are unclear or even conflicting. However, a few general thoughts:

  1. If the amount of data in the cache would not be large, I would not bother with local storage--I would just store it in some application-level scope (global variable, application context, etc.). If the application restarts, the cache would have to be pulled from the database fresh (I would imagine that would be desirable anyway).

  2. Usually, objects that are cached are read-only (can't be changed by the user). If a user does change an object that would be cached, you would generally want to persist that information to the server/database immediately, so that other clients can get that information.

  3. If the server/database holds the "master" cached data, and needs to notify clients in the case of a data change, the silverlight app will likely have to be a subscribed listener to a service of some sort (MSMQ may actually work as a back end). If the updates don't have to be in real time, consider the cache simply refreshing itself on a timer, every 5-10 minutes or so.

情徒 2024-10-23 18:58:45

有很多关于双工 WCF 服务(通过 HTTP)的示例 - 也许寻找 Silverlight 的发布/订阅模式实现会给您一个良好的开端。

诚然,我无法为您的场景提供示例实现,但这里有一些可能值得一看的地方:

Laharsub:一条消息实时网络应用程序的服务器
PollingDuplexHttpBinding 和发布订阅框架

There are quite a number of examples out there concering duplex WCF services (over HTTP) - maybe looking for publish/subscribe pattern implementations for Silverlight will give you a head start.

Admittedly I can't provide a sample implementation for your scenario but here are some places that may be worth looking to:

Laharsub: a message server for real time web applications
PollingDuplexHttpBinding and a Publish subscribe framework

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