Reputation: 13742
I am re-building a news portal of which already have a large number of visits every day. One of the major concerns when re-building this site was to maximize performance and speed.
Having said this, we have done many things from caching, to all sort of other measures to ensure speed.
Now towards the end of the project, I am having a dilemma of where to store my site settings that would least affect performance.
The site settings will include things such as: Domain, DefaultImgPath, Google Analytics code, default emails of editors as well as more dynamic design/display feature settings such as the background color of specific DIVs and default color for links etc..
As far as I know, I have 4 choices in storing all these info.
Database: Storing general settings in the DB and caching them may be a solution however, I want to limit the access to the database for only necessary and essential functions of the project which generally are insert/update/delete news items, author articles etc..
XML: I can store these settings in an XML file but I have not done this sort of thing before so I don't know what kind of problems -if any- I might face in the future.
CONFIG: I can also store these settings in web.config
CLASS FILE: I can hard code all these settings in a SiteSettings class, but since the site admin himself will be able to edit these settings, It may not be the best solution.
Currently, I am more close to choosing web.config but letting people fiddle with it too often is something I do not want. E.g. if somehow, I miss out a validation for something and it breaks the web.config, the whole site will go down.
My concern basically is that, I cannot forsee any possible consequences of using any of the methods above (or is there any other?), I was hoping to get this question over to more experienced people out here who hopefully help make my decision.
Upvotes: 2
Views: 553
Reputation: 9166
In this situation I would go for the Db Server + Cache solution.
The reason for my opininon is that using a database, you can store meta info about every configuration change. For instance it would probably be good to store info about:
This makes it easier to restore the site to a previous configuration state when you or the site admin or whoever manages to break the confiuration. Simply inactivate all the changes done after some known time when the site was working and flush the cache.
Just to clarify what I mean: I would NOT have a db table where the configuration name was the primary key/unique. Instead I would have a surrogate key, and append rows whenever a configuration setting is changed. The cache version would alway hold the most recent active value per configuration key. So when changing a setting, send it off to the db as a new record and update the cache.
About the other alternatives:
I would NOT allow the site admin to change the web.config files. That is just asking for trouble.
Using a SiteSettings class file is not going to work well either, at least not with hard coded values. If the changes are going to be presisted so they remain active even after a server restart, you will still have to store that change somewhere else.
Using a custom Xml file (or generally a file of some sort) could work. This file could contain the same information that I suggested you include in the Database version. But it would require much more care in order to handle possible concurrent edits.
So in my opinion, storing in db is probably going to be the easiest and most reliable way.
Edit: I have assumed in my answer that there is some sort of interface where you can do configuration updates. That is, I assume that updates should be possible to do "on the fly" without having to restart the application. If this is not the case, and there is no specific interface for updating conf data, the database version might be less feasible because manually updating a db is more difficult for laypersons than simply editing a file somewhere on disc.
Edit 2: I would definitely create one or a few classes in order to interact with the cache. Probably I'd create one class (maybe ConfSettings
) with named properties which can be initialized and stored in cache (cache defined broadly - Asp.Net server cache, application scope, stored in static class etc). And one class (ConfSettingsManager
or similar) for accessing the cached object, storing updates and flushing the cached object etc.
Upvotes: 1
Reputation: 28970
try with this code (global parametrized variable )
<appSettings>
<add key="YourKey1" value="Your value 1" />
<add key="YourKey2" value="Your value 2" />
</appSettings>
And this code for getting ( Add reference to System.Configuration, API configuration )
var yourValue1 = ConfigurationSettings.AppSettings["YourKey1"];
var yourValue2 = ConfigurationSettings.AppSettings["YourKey2"];
Upvotes: 2