Smart Client with local (database) cache

Smart Client with local (database) cache

Old forum URL: forums.lhotka.net/forums/t/1621.aspx


Mat posted on Sunday, October 29, 2006

I've been fiddling about with CSLA and am quite happy with it so far. It seems somewhat more versatile than other frameworks I've tried. There are a few related forum posts, but nothing concrete on the following scenario, which must be fairly common?

I want to create a Smart Client application with a full-fledged local SQL Server Express (or similar) database cache. The scenario is many clients connecting to a central database server, where each client will only replicate the (small) portion of the database in which it is interested.

The basic premise is that the client tries to retrieve data from the local cache. If it cannot be found, it connects to the server to get the data, dumps it in the local cache, return it to the user. Simple enough, but how would this fit into CSLA?

I'm thinking along the following lines, but is there a better way? Have I missed something obvious?
  1. Catch missing data exceptions in the DataPortal_Fetch function (this seems most promising)
  2. Catch missing data exceptions from the data portal in the factory methods (with this I'd end up putting my remote database access code in the 'wrong' place)
  3. Catch missing data in 1 or 2 in another way than exceptions (this could be faster?)
  4. Jiggery-pokery inside the framework to support multiple locations to load data from (haven't a clue about this one)
Replication of updates to the central database can be handled in a similar manner, with the server-end catching collisions between users, etc.

I'd appeciate any comments on the above, is this even sensible and do-able?

Thanks

Mat

Brian Criswell replied on Sunday, October 29, 2006

First of all, create a second database connection in your Database object (check the PTracker example for an example of the Database object).  Each object that could be fetched from both locations would implement an Exists method (check PTracker for examples).  In your fetch method, call Exists() to check if the item exists in the local cache.  If it exists, use the local connection, otherwise, use the remote connection.  This does mean an extra database call, but it will be to your local database, so the performance hit should be negligible.

Mat replied on Monday, October 30, 2006

Thanks Brian, I'll take a look at that as soon as I get round some other niggles I've been getting bogged down in today (DataBinding EditLevels).


Copyright (c) Marimer LLC