开发者

Best method to maintain in-memory cache of DB objects in Silverlight

开发者 https://www.devze.com 2023-02-09 21:50 出处:网络
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

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开发者_如何学JAVA, 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!


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.


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

0

精彩评论

暂无评论...
验证码 换一张
取 消