开发者

Properly saving XDocument

I have a custom data service in my website , which is supposed to refresh data every 10 minutes without any downtime for users. ( asp.net mvc3 , mssql 2008 , c# )

At the moment it's refreshing data every 10 minutes and updating my database ( mssql ) no problem. But the thing is , instead of reading data off db for every user request , I want to save it to a XML file right after refreshing data so users can get it without any extra db connection or process.

So there will be one process regathering data and w开发者_StackOverflow社区riting to XML meanwhile lots of user will be requesting that XML every second.

Since I don't know much about File Write/Read stuff , I'm not sure if I should lock file before writing it , because other processes may be reading it. Or maybe it's OK since just one process will be writing and others reading/requesting it won't create any problems? Also not sure if the Save function of XDocument already has lock before writing in it.

So , all in all ; how can i safely save my XDocument objet into a xml file while any other processes may be reading/requesting that file?

OR should I just read data from Sql ( nevermind the process time&delay for every user) and return XDocument object , which would be easier I guess?

Thanks in advance!


I think it's a bad idea to write the XML out to a file - it might not even be faster to read it back than calling the DB. Instead I'd use the ASP.NET caching infrastructure, i.e. using the Cache class to cache the data in memory - this will be much faster.


You have a database which is designed, tested and built to deliver data to the users, why do you want to save data out from it and implement your own file system based database?

I think the last option you have mentioned is the best, just connect to the database and retrieve the XML to the users as needed. If you have efficient queries and a solid DataAccessLayer the db will perform well.


Another option is using a caching mechanism such as memcache or AppFabric Cache.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜