Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I'm going to develop a fairly basic re-usable blog component, with simple CRUD operations using ASP.Net.

Which method of storing blog posts would be best suited to the situation in terms of performance/maintainability?

  • Create an XML file and store data in filesystem, filesize will not likely be any more than 50kb in size
  • Store blog post data in DB, retrieve as needed

Am I right in assuming that the asp.net runtime will cache the .xml files and only clear them/request a fresh copy when their contents are changed? Or do you have to explicitly add the file to the cache? If this is the case would this offer the best performance over storing the data in the database?

share|improve this question

3 Answers 3

up vote 12 down vote accepted

Use a database, thats what they are for. File storage has its place, but I wouldnt use it for this kind of scenario. Consider, for example, getting a list of blog posts containing a certain tag. Doing that with a database is trivial - likely just a single SQL statement. Doing it with files will involve a lot of file manipulation.

share|improve this answer
    
You're probably right. In addition, if i went the .xml route, i'd have to store an ID or something unique in the file to tie that post to comments/tags etc.. which could become quite messy +1 –  DGibbs Apr 29 '13 at 19:18
    
There are many other reasons, but yes, a database is the way to go. –  Robert Harvey Apr 29 '13 at 19:26

Am I right in assuming that the asp.net runtime will cache the .xml files and only clear them/request a fresh copy when their contents are changed? Or do you have to explicitly add the file to the cache?

No, that isn't a valid assumption. You must opt in to caching and come up with a system for invalidation.

If this is the case would this offer the best performance over storing the data in the database?

It's all about the memory vs bandwidth vs processing time tradeoff. You'll need to define what you value in performance before anyone could tell you whether it'll be the best. If you value CPU and bandwidth more than memory, then definitely.

share|improve this answer

You could adopt a hybrid approach, by storing the structured, metadata of each blog post in a database, and then store the raw text on your file-system (or in a blob-store). Storing the metadata in a database allows you to perform queries for blogs by title, date, tag, user, etc. in a very straightforward way, while allowing the text size of your blog posts to be unbounded. This may be of interest since you stated that this was intended to be part of a reusable blog component.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.