views:

391

answers:

2

I am working on an application that depends on a MySQL database for parts of the content. In some cases, the application will run in an environment with limited internet connectivity (UMTS), in particular suffering from high latencies.

A user of the application is able to login, and most of the content for the user interface of the application is retrieved from a MySQL database. To prevent delays after a user logs in, I would like to cache as much of the database content at the client side as possible. New content should only be retrieved from the database in case a relevant change was made. Is there a common way to approach this problem? Any literature that describes solid solutions to this problem?


Small update: I am now looking into CouchDB as the solution for my particular use-case. The main reason being that:

it allows for users and servers to access and update the same shared data while disconnected and then bi-directionally replicate those changes later.

(from: http://couchdb.apache.org/docs/overview.html)

So far it looks really promising.

+2  A: 

We actually run a local copy of the database and have most of the software just talk to the local database which is always available. Then we have a background process that works to keep the two databases in sync.

I will warn you that any type of local caching is not for the faint of heart. There are soooo many ways it can get out of sync. Avoid doing it if you can.

Kevin Gale
How about using replication to keep the databases in sync? I just read up on it, and it seems promising...
Ton van den Heuvel
If you can find a replication solution that's great. In our case we run Firebird locally (It's a truly great embedded or semi-embedded database) and there are a few different databases we use on the server. We couldn't find any replication that worked with all the combinations so we rolled our own.
Kevin Gale
Using a local database with the same schema also has another advantage. You can pretty easily code the application so it can either point to a local database or to the server. So in cases where you don't need the local cache you just point at the server.
Kevin Gale
I also feel I should warn you again that this isn't simple. Our application requires it so we take the pain. But it is painful. I'm envious of applications that don't have to worry about data being out of sync.
Kevin Gale
Thanks for your suggestions. I'm planning on using a local database with the same schema as the database server just like you suggested. I can avoid a lot of synchronization problems since there are only a few tables the client will write to that are read-only for the server and vice versa. Still, there will be synchronization issues since I have multiple clients writing to the same tables. Record order does not matter for those tables, so it will be a relatively easy problem to solve.
Ton van den Heuvel
A: 

I'm not sure if this is common practice, but you could write the cached data to a JavaScript file that the client would cache. Then you can make Ajax calls to see if there have been any changes... Which would be a small request. If no changes, use the cached data.

Mike Sherov