Pergunta

I need to store about 100 settings for an website. I can either save it as one row in a db or save it as a JSON file and have each page read in the settings and update the file when the setting change. Or I can just read it into the page via db call. Which would be a preferred method? I'm trying to maximize performance.

****EDIT This is a standard website. A home page and about 10 other pages. About, contact, blah, blah, blah.. Each page has the same info/theme settings is will use. This info can be updated by the website owner. Below is the config, so for example... One day the owner decides to change the color of his footer. He would make the change and it would write to the color_footer key to save the changes.

Here is an example config file. This seems like too little to make a db call. Thoughts?

$GLOBALS = array(
"theme" => array(
    "color_scheme" => "#429a44",
    "color_body" => "#ffffff",
    "color_nav" => "#333333",
    "color_footer" => "#333333",
    "page_width_front" => "max-width: 100%;",
    "page_width_inner" => "max-width: 1024px;",
    "font_color_scheme" => "#ffffff",
    "font_color_body" => "#ffffff",
    "font_color_nav" => "#ffffff",
    "font_body" => "font-family: 'Francois One', sans-serif;",
    "font_nav" => "font-family: 'Open Sans', sans-serif;",
    "font_body_size" => "font-size: 15px;",
    "font_nav_size" => "font-size: 25px;",
    "slider_width" => "max-width: 1024px; margin: auto;",
    "slider_interval" => "5000"
),
"social_links" => array(
    "facebook" => "",
    "twitter" => "",
    "instagram" => "",
    "youtube" => "",
    "flickr" => "",
    "pinterest" => "",
    "google-plus" => "",
    "foursquare" => "",
    "linkedin" => "",
    "tumbler" => "",
    "vimeo" => ""
),

);

Foi útil?

Solução

First want to confirm: Is there only 1 setting profile(~100 settings in it) for the whole website? Or 1 setting profile(~100 settings in it) for each page in the website?

If only 1 profile: (1)For storage, I think either DB or JSON file on disk is OK; (2)But you mention that each page access will read the profile, if the access frequence is high, you should keep the profile in memory(Just a object, converted from JSON string). And remember to write back to DB/Disk when update.

If 1 profile for each page:

For access proformance, you can try to adopt some cache product(eg. Redis)

Actually I am confused about your design. Why keeping such a setting?

Outras dicas

If your data has a simple tabular structure and its going to be the same, then relational model could be adequate, but if the structure of your data is too complex and has multiple levels, than you must go for nosql or JSON structure to store your data. The other thing that you have to keep in mind is the amount of data you'll be storing. The number of rows in RDBMS case, because up to a certain limit, RDBMS will perform faster then almost all NoSQLs but as your data gorws, fetching from a NoSQL like Cassandra or Mongo will be faster than fetching from mysql.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top