- global $a;
-
- // To-Do: How to integrate APC here?
-
- $r = q("SELECT * FROM `config` WHERE `cat` = '%s'", dbesc($family));
- if(count($r)) {
- foreach($r as $rr) {
- $k = $rr['k'];
- if ($family === 'config') {
- $a->config[$k] = $rr['v'];
- } else {
- $a->config[$family][$k] = $rr['v'];
- }
- }
- } else if ($family != 'config') {
- // Negative caching
- $a->config[$family] = "!<unset>!";
- }
-}}
-
-// get a particular config variable given the family name
-// and key. Returns false if not set.
-// $instore is only used by the set_config function
-// to determine if the key already exists in the DB
-// If a key is found in the DB but doesn't exist in
-// local config cache, pull it into the cache so we don't have
-// to hit the DB again for this item.
-
-if(! function_exists('get_config')) {
-function get_config($family, $key, $instore = false) {
-
- global $a;
-
- if(! $instore) {
- // Looking if the whole family isn't set
- if(isset($a->config[$family])) {
- if($a->config[$family] === '!<unset>!') {
- return false;
- }
- }
-
- if(isset($a->config[$family][$key])) {
- if($a->config[$family][$key] === '!<unset>!') {
- return false;
- }
- return $a->config[$family][$key];
- }
- }
-
- // If APC is enabled then fetch the data from there
- if (function_exists("apc_fetch") AND function_exists("apc_exists"))
- if (apc_exists($family."|".$key)) {
- $val = apc_fetch($family."|".$key);
- //logger("APC: fetched stored value ".$family."|".$key, LOGGER_DEBUG);
- $a->config[$family][$key] = $val;
-
- if ($val === '!<unset>!')
- return false;
- else
- return $val;
- } else
- //logger("APC: cache miss for value ".$family."|".$key, LOGGER_DEBUG);
-
-
- $ret = q("SELECT `v` FROM `config` WHERE `cat` = '%s' AND `k` = '%s' LIMIT 1",
- dbesc($family),
- dbesc($key)
- );
- if(count($ret)) {
- // manage array value
- $val = (preg_match("|^a:[0-9]+:{.*}$|s", $ret[0]['v'])?unserialize( $ret[0]['v']):$ret[0]['v']);
- $a->config[$family][$key] = $val;
-
- // If APC is enabled then store the data there
- if (function_exists("apc_store"))
- apc_store($family."|".$key, $val, 600);
-
- return $val;
- }
- else {
- $a->config[$family][$key] = '!<unset>!';
-
- // If APC is enabled then store the data there
- if (function_exists("apc_store"))
- apc_store($family."|".$key, '!<unset>!', 600);
- }
- return false;
-}}