Would enumerating folder contents and checking the existance of several files on each web request be a serious performance penaly?
As an extensibility option for my web application I would like to allow the user to add sections to it by simply making new folders and uploading files to them. So, for instance, if they created (in the webroot):
/UserContent/StaticPages/First/Second/index.txt
Then in the main menu there would be a new menu point "First" with the submenu point "Second", which would lead to markdown-parsed version of index.txt. This way the user can upload any static menu points he wants (such as "About us", "Contact us", "Our Mission" etc.)
Another extensibility point is that I would like them to add headers/footers to specific webpages in a similar fashion. I'm using ASP.NET MVC3, so there are pretty URLs, and it would be easy for the user to just create:
/UserContent/Additions/Store/Categories/35/header.txt
And when someone opened www.mydomain.com/Store/Categories/35
the markdown-parsed header.txt would be prepended.
This is simple for the user, and simple for me (I don't need to make sophisticated admin panels and WYSIWYG editors).
However I'm worried about the performance. This scheme means that on each GET request I would need to scan the /UserContent/StaticPages
folder and check for the existences of the header/footer files (several, because parent levels can have their header.txt/footer.txt as well).
I could cache the result, but then I have to manage the cache and the user will need to know that changes can take up to X minutes to display. Would this be a premature optimiz开发者_StackOverflow中文版ation? There won't be much data in those folders, so Windows will probably be able to easily cache their contents itself.
You should take some measurements to see if the performance becomes too bad.
From my experience you should not try too hard to make everything as fast as possible NOW (i.e. don't waste too much time if you don't know yet that it's worth it). But choose a way that more or less doesn't prevent doing it later. So e.g. don't use instances of File all over your code because that means a lot of work for you later on if you have to change the approach. Find some thin abstractions where you are worried about the specific approach.
Try profiling some typical use cases with the expected usage volume (load tests) and you may soon know if and what you need to optimize.
精彩评论