Reputation: 12985
Is it recommended to store certain data in a config-file while referencing to it by ID in database? Specifically, when storing information that's rarely or never updated.
For example, I may have different roles for users in my application. As these roles are hardly ever (or never) updated, is it really necessary to store them in a roles
-table and reference to them by ID in users
? I could as well have the roles defined in an array. This way the database wouldn't need to be called every time to get role information (which is required on every page).
Another option would be to cache the whole bunch of role-information from the database. Not sure if this is any better than simply having an array stored somewhere.
The same question can be asked when storing any application-related data that's not edited by the users but the developers.
Upvotes: 1
Views: 153
Reputation: 52117
Another option would be to cache the whole bunch of role-information from the database. Not sure if this is any better than simply having an array stored somewhere.
It isn't until you have a bug in the application, a network failure or a good-old power cut. At that point, the cached solution will just re-read the "master" data from the database and keep churning away, safe in the knowledge that data was protected by database transactions and backup regime.
If such calamity befell "separate array" solution, it could corrupt the array storage or make it inconsistent with the rest of the data (no referential integrity).
On top of that, storing data centrally means changes are automatically visible to all clients. You can store files "centrally" via shared folders or FTP and such, but why not use the database if it's already there?
Upvotes: 1