All pastes #135119 Raw Edit

variable cache

public php v1 · immutable
#135119 ·published 2006-08-16 18:28 UTC
rendered paste body
=== modified file 'includes/bootstrap.inc'--- includes/bootstrap.inc	+++ includes/bootstrap.inc	@@ -244,7 +244,7 @@ function variable_init($conf = array())      $variables = unserialize($cached->data);   }   else {-    $result = db_query('SELECT * FROM {variable}');+    $result = db_query('SELECT * FROM {variable} WHERE status = 1');     while ($variable = db_fetch_object($result)) {       $variables[$variable->name] = unserialize($variable->value);     }@@ -265,12 +265,19 @@ function variable_init($conf = array())   *   The name of the variable to return.  * @param $default  *   The default value to use if this variable has never been set.+ * @param $cached+ *   Boolean value which determines if this variable can be retrieved from the variable cache.  * @return  *   The value of the variable.  */-function variable_get($name, $default) {+function variable_get($name, $default, $cached = TRUE) {   global $conf; +  if (!$cached) {+    if ($value = db_result(db_query("SELECT value FROM {variable} WHERE name = '%s'", $name))) {+      $conf[$name] = unserialize($value);+    }+  }   return isset($conf[$name]) ? $conf[$name] : $default; } @@ -282,13 +289,17 @@ function variable_get($name, $default) {  * @param $value  *   The value to set. This can be any PHP data type; these functions take care  *   of serialization as necessary.+ * @param $cached+ *   Boolean value which determines if this variable will be placed into the variable cache.  */-function variable_set($name, $value) {+function variable_set($name, $value, $cached = TRUE) {   global $conf; +  $status = $cached ? 1 : 0;+   db_lock_table('variable');   db_query("DELETE FROM {variable} WHERE name = '%s'", $name);-  db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));+  db_query("INSERT INTO {variable} (name, value, status) VALUES ('%s', '%s', %d)", $name, serialize($value), $status);   db_unlock_tables();    cache_clear_all('variables');