how can I save/keep-in-sync an in-memory graph of objects with the database?
Posted
by Greg
on Stack Overflow
See other posts from Stack Overflow
or by Greg
Published on 2010-04-27T20:27:07Z
Indexed on
2010/04/27
21:03 UTC
Read the original article
Hit count: 288
Question - What is a good best practice approach for how can I save/keep-in-sync an jn-memory graph of objects with the database?
Background:
That is say I have the classes Node and Relationship, and the application is building up a graph of related objects using these classes. There might be 1000 nodes with various relationships between them. The application needs to query the structure hence an in-memory approach is good for performance no doubt (e.g. traverse the graph from Node X to find the root parents)
The graph does need to be persisted however into a database with tables NODES and RELATIONSHIPS.
Therefore what is a good best practice approach for how can I save/keep-in-sync an jn-memory graph of objects with the database?
Ideal requirements would include:
- build up changes in-memory and then 'save' afterwards (mandatory)
- when saving, apply updates to database in correct order to avoid hitting any database constraints (mandatory)
- keep persistence mechanism separate from model, for ease in changing persistence layer if needed, e.g. don't just wrap an ADO.net DataRow in the Node and Relationship classes (desirable)
- mechanism for doing optimistic locking (desirable)
Or is the overhead of all this for a smallish application just not worth it and I should just hit the database each time for everything? (assuming the response times were acceptable) [would still like to avoid if not too much extra overhead to remain somewhat scalable re performance]
© Stack Overflow or respective owner