How to store site wide settings in a database?

前端 未结 9 2915
时光说笑
时光说笑 2021-02-19 10:08

I\'m debating three different approaches to to storing sitewide settings for a web application.

A key/value pair lookup table, each key represents a setting.

    <
9条回答
  •  时光说笑
    2021-02-19 10:30

    I would go with the first option -- key/value pair lookup table. It's the most flexible and scalable solution, in my opinion. If you are worried about the cost of running many queries here and there to retrieve various config values, you could always implement some sort of cache, such as loading the whole table at once into memory. In addition to key and value, you could add columns such as "Description", and "Default Value", etc., and build a generic configuration editor that displays the Descriptions, etc., on-screen to help the user edit the config values.

    I've seen some commercial applications with a single-row config table, and while I don't have direct experience doing development work against it, it struck me as much less scalable and harder to read.

提交回复
热议问题