Question

I need to store a global/class variable that is updated by managers from a web dashboard. The variable will be an array, lets call it car_types. About once a week managers need to go in and change the value. So maybe they'll update from ['suv', 'convertible', 'sedan'] to ['suv', 'convertible'].

What I'm not sure on is where to store this variable. I could certainly create a database table with one record in it that gets updated, but that seems like overkill. We use memecached, so I could send the variable there, though I'm not sure if thats persistent enough. I was thinking of having the dashboard update a class variable, but we have dozens of servers running the same app, and I'm unclear if the change would be replicated to all boxes or just stay on one box.

thanks

Was it helpful?

Solution

Global variables are prefixed by $, example: $cars

But What if your application goes down? The global var is reinitialized to its default value. I would recommend a database, eventually with caching if you want to save on performances.

You could cache your database values in you $cars variable

That's my personal approach: database + cache for records that being updated not often. cache is cleared when a change is made in the table, and cache is created (with a db request) during first fetch of the record.

As a result its all good cause you have the flexibility to change the records sometimes, no problem arise when the server goes down, or with multi-threading, and the cache permit not to kill performances

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top