Reputation: 3416
Say I have a config.php file which contains definitions for a bunch of preferences. My init scripts loads these values into memory.
Say instead of loading them into memory, I loaded them into apc. How would I force apc to update the variables when I changed the contents of config.php manually? Would I need to create a utility script of some sort which performed the change so it could insure cached variables were updated automatically?
If a variable exists within apc, and a new variable is added with the same name as the existing (an updated version) is the old caches value overwritten?
Upvotes: 0
Views: 1368
Reputation: 51411
How would I force apc to update the variables when I changed the contents of config.php manually?
You have a few options here.
apc_store
, you can set a "time to live" value in seconds. You can, say, set each of your configuration values to last exactly five minutes. When once is missing (apc_exists
), then you can trigger the code that regenerates and recaches them.apc_delete
on the keys.apc_store
itself.The first is lowest effort, the second is the most sane, and the third and fourth are probably the right thing to do assuming that configuration updates are programmatic things instead of completely manual things, as you imply here.
If configuration updates are always manual, it would be worth writing a tiny script you can manually invoke that simply clears or updates the cache.
That said, to be very frank, the cost of parsing a pure-PHP config file on every pageview is nonexistant if you're also using APC as an bytecode cache. In that circumstance, caching the values defined within is downright silly.
If a variable exists within apc, and a new variable is added with the same name as the existing (an updated version) is the old caches value overwritten?
Correct, unless you're using apc_add
instead of apc_store
.
Upvotes: 1