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?
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.
2
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.
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.