I was thinking about a way to allow multiple users to get CRUD access to an XML document in an asp.net app. The operations would obviously have to be made under the assumption of a multithreaded environment.
For perf reasons, would it make sense to cache the document, and use a mutex on that cached version? When would changes be flushed to the physical XML开发者_C百科 document?
Any and all recommendations are appreciated (also "use a database" isn't an option at this point unfortunately)
It certainly makes sense to cache the XML document, so you do not need to read it from disk for each user / request. You should synchronize access to it. A good idea would be to encapsulate access in a single class, and use a ReaderWriterLockSlim for synchronization. When reading data, acquire a read lock and read from memory. When writing, acquire a write lock, write data and replace the in-memory copy.
You could serialize your cached version of your DB object to the disk (as binary) after every transaction and only write the XML at certain intervals.
精彩评论