Commit 38ee8103 authored by Jeremy's avatar Jeremy

Cleanup, remove old files not in D6.

parent 1c34d9f2
// $Id$
// Global Killswitch
if (Drupal.jsEnabled) {
$(document).ready(function() {
$("body").append($("#memcache-devel"));
});
}
<?php
// $Id$
function memcache_init() {
if (strstr($_SERVER['PHP_SELF'], 'update.php') || strstr($_GET['q'], 'autocomplete')) {
// update.php relies on standard error handler
}
else {
if (user_access('access memcache statistics')) {
drupal_add_js(drupal_get_path('module', 'memcache'). '/memcache.js');
register_shutdown_function('memcache_shutdown');
}
}
}
function memcache_perm() {
return array('access memcache statistics');
}
/**
* See memcache_init() which registers this function as a shutdown function.
* Displays memcache stats in the footer.
*/
function memcache_shutdown() {
global $user, $_memcache_statistics;
// Try not to break non html pages.
if (function_exists('drupal_get_headers')) {
$headers = drupal_get_headers();
if(strstr($headers, 'xml') || strstr($headers, 'javascript') || strstr($headers, 'plain')) {
return;
}
}
if (user_access('access memcache statistics')) {
$stats = array();
foreach ($_memcache_statistics as $stat => $val) {
$stats[] = "<strong>$stat:</strong> ". theme('item_list', $val);
}
if (!empty($stats)) {
$output = theme('item_list', $stats);
// this makes sure all of the HTML is within the <body> even though this <script> is outside it
print '<div id="memcache-devel"><h2>'. t('Memcache statistics'). '</h2>'. $output.'</div>';
}
}
}
diff -ur includes/bootstrap.inc includes/bootstrap.inc
--- includes/bootstrap.inc 2007-01-15 03:52:02.000000000 -0800
+++ includes/bootstrap.inc 2008-01-29 14:05:04.000000000 -0800
@@ -339,14 +339,14 @@
function variable_init($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
if ($cached = cache_get('variables', 'cache')) {
- $variables = unserialize($cached->data);
+ $variables = $cached->data;
}
else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
- cache_set('variables', 'cache', serialize($variables));
+ cache_set('variables', 'cache', $variables);
}
foreach ($conf as $name => $value) {
@@ -841,7 +841,8 @@
* Drupal's bootstrap process.
*/
function _drupal_cache_init($phase) {
- require_once variable_get('cache_inc', './includes/cache.inc');
+ $cache_inc = variable_get('cache_inc', './includes/cache.inc');
+ require_once $cache_inc;
if ($phase == DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE && variable_get('page_cache_fastpath', 0)) {
if (page_cache_fastpath()) {
Only in includes: bootstrap.inc.orig
diff -ur includes/cache.inc includes/cache.inc
--- includes/cache.inc 2006-11-09 23:26:27.000000000 -0800
+++ includes/cache.inc 2008-01-29 14:05:04.000000000 -0800
@@ -21,12 +21,15 @@
variable_set('cache_flush', 0);
}
- $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {%s} WHERE cid = '%s'", $table, $key));
+ $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {%s} WHERE cid = '%s'", $table, $key));
if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data.
if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
// If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the
@@ -40,6 +43,9 @@
}
else {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
}
return $cache;
@@ -78,8 +84,8 @@
* The table $table to store the data in. Valid core values are 'cache_filter',
* 'cache_menu', 'cache_page', or 'cache'.
* @param $data
- * The data to store in the cache. Complex data types must be serialized first.
- * @param $expire
+ * The data to store in the cache. Complex data types will be automatically serialized before insertion.
+ * Strings will be stored as plain text and not serialized. * @param $expire
* One of the following values:
* - CACHE_PERMANENT: Indicates that the item should never be removed unless
* explicitly told to using cache_clear_all() with a cache ID.
@@ -91,10 +97,15 @@
* A string containing HTTP header information for cached pages.
*/
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
+ $serialized = 0;
+ if (is_object($data) || is_array($data)) {
+ $data = serialize($data);
+ $serialized = 1;
+ }
db_lock_table($table);
- db_query("UPDATE {%s} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $table, $data, time(), $expire, $headers, $cid);
+ db_query("UPDATE {$table} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid);
if (!db_affected_rows()) {
- @db_query("INSERT INTO {%s} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $table, $cid, $data, time(), $expire, $headers);
+ @db_query("INSERT INTO {$table} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized);
}
db_unlock_tables();
}
@@ -164,4 +175,3 @@
}
}
}
-
diff -ur includes/menu.inc includes/menu.inc
--- includes/menu.inc 2007-01-13 17:37:48.000000000 -0800
+++ includes/menu.inc 2008-01-29 14:05:04.000000000 -0800
@@ -208,12 +208,12 @@
$cid = "$user->uid:$locale";
if ($cached = cache_get($cid, 'cache_menu')) {
- $_menu = unserialize($cached->data);
+ $_menu = $cached->data;
}
else {
_menu_build();
// Cache the menu structure for this user, to expire after one day.
- cache_set($cid, 'cache_menu', serialize($_menu), time() + (60 * 60 * 24));
+ cache_set($cid, 'cache_menu', $_menu, time() + (60 * 60 * 24));
}
// Make sure items that cannot be cached are added.
diff -ur modules/locale/locale.module modules/locale/locale.module
--- modules/locale/locale.module 2006-12-27 05:11:59.000000000 -0800
+++ modules/locale/locale.module 2008-01-29 14:05:04.000000000 -0800
@@ -172,7 +172,7 @@
locale_refresh_cache();
$cache = cache_get("locale:$locale", 'cache');
}
- $locale_t = unserialize($cache->data);
+ $locale_t = $cache->data;
}
// We have the translation cached (if it is TRUE, then there is no
@@ -231,7 +231,7 @@
while ($data = db_fetch_object($result)) {
$t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
}
- cache_set("locale:$locale", 'cache', serialize($t));
+ cache_set("locale:$locale", 'cache', $t);
}
}
diff -ur includes/bootstrap.inc includes/bootstrap.inc
--- includes/bootstrap.inc 2007-01-15 03:52:02.000000000 -0800
+++ includes/bootstrap.inc 2008-01-29 14:03:03.000000000 -0800
@@ -339,14 +339,14 @@
function variable_init($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
if ($cached = cache_get('variables', 'cache')) {
- $variables = unserialize($cached->data);
+ $variables = $cached->data;
}
else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
- cache_set('variables', 'cache', serialize($variables));
+ cache_set('variables', 'cache', $variables);
}
foreach ($conf as $name => $value) {
@@ -841,7 +841,8 @@
* Drupal's bootstrap process.
*/
function _drupal_cache_init($phase) {
- require_once variable_get('cache_inc', './includes/cache.inc');
+ $cache_inc = variable_get('cache_inc', './includes/cache.inc');
+ require_once $cache_inc;
if ($phase == DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE && variable_get('page_cache_fastpath', 0)) {
if (page_cache_fastpath()) {
Only in includes: bootstrap.inc.orig
diff -ur includes/cache.inc includes/cache.inc
--- includes/cache.inc 2006-11-09 23:26:27.000000000 -0800
+++ includes/cache.inc 2008-01-29 14:03:03.000000000 -0800
@@ -21,12 +21,15 @@
variable_set('cache_flush', 0);
}
- $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {%s} WHERE cid = '%s'", $table, $key));
+ $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {%s} WHERE cid = '%s'", $table, $key));
if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data.
if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
// If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the
@@ -40,6 +43,9 @@
}
else {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
}
return $cache;
@@ -78,8 +84,8 @@
* The table $table to store the data in. Valid core values are 'cache_filter',
* 'cache_menu', 'cache_page', or 'cache'.
* @param $data
- * The data to store in the cache. Complex data types must be serialized first.
- * @param $expire
+ * The data to store in the cache. Complex data types will be automatically serialized before insertion.
+ * Strings will be stored as plain text and not serialized. * @param $expire
* One of the following values:
* - CACHE_PERMANENT: Indicates that the item should never be removed unless
* explicitly told to using cache_clear_all() with a cache ID.
@@ -91,10 +97,15 @@
* A string containing HTTP header information for cached pages.
*/
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
+ $serialized = 0;
+ if (is_object($data) || is_array($data)) {
+ $data = serialize($data);
+ $serialized = 1;
+ }
db_lock_table($table);
- db_query("UPDATE {%s} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $table, $data, time(), $expire, $headers, $cid);
+ db_query("UPDATE {$table} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid);
if (!db_affected_rows()) {
- @db_query("INSERT INTO {%s} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $table, $cid, $data, time(), $expire, $headers);
+ @db_query("INSERT INTO {$table} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized);
}
db_unlock_tables();
}
@@ -164,4 +175,3 @@
}
}
}
-
diff -ur includes/menu.inc includes/menu.inc
--- includes/menu.inc 2007-01-13 17:37:48.000000000 -0800
+++ includes/menu.inc 2008-01-29 14:03:03.000000000 -0800
@@ -208,12 +208,12 @@
$cid = "$user->uid:$locale";
if ($cached = cache_get($cid, 'cache_menu')) {
- $_menu = unserialize($cached->data);
+ $_menu = $cached->data;
}
else {
_menu_build();
// Cache the menu structure for this user, to expire after one day.
- cache_set($cid, 'cache_menu', serialize($_menu), time() + (60 * 60 * 24));
+ cache_set($cid, 'cache_menu', $_menu, time() + (60 * 60 * 24));
}
// Make sure items that cannot be cached are added.
diff -ur modules/locale/locale.module modules/locale/locale.module
--- modules/locale/locale.module 2006-12-27 05:11:59.000000000 -0800
+++ modules/locale/locale.module 2008-01-29 14:03:03.000000000 -0800
@@ -172,7 +172,7 @@
locale_refresh_cache();
$cache = cache_get("locale:$locale", 'cache');
}
- $locale_t = unserialize($cache->data);
+ $locale_t = $cache->data;
}
// We have the translation cached (if it is TRUE, then there is no
@@ -231,7 +231,7 @@
while ($data = db_fetch_object($result)) {
$t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
}
- cache_set("locale:$locale", 'cache', serialize($t));
+ cache_set("locale:$locale", 'cache', $t);
}
}
diff -ur includes/bootstrap.inc includes/bootstrap.inc
--- includes/bootstrap.inc 2007-07-26 12:16:45.000000000 -0700
+++ includes/bootstrap.inc 2008-01-29 13:56:54.000000000 -0800
@@ -382,14 +382,14 @@
function variable_init($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
if ($cached = cache_get('variables', 'cache')) {
- $variables = unserialize($cached->data);
+ $variables = $cached->data;
}
else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
- cache_set('variables', 'cache', serialize($variables));
+ cache_set('variables', 'cache', $variables);
}
foreach ($conf as $name => $value) {
Only in includes: bootstrap.inc.orig
diff -ur includes/cache.inc includes/cache.inc
--- includes/cache.inc 2007-06-26 20:35:48.000000000 -0700
+++ includes/cache.inc 2008-01-29 13:56:54.000000000 -0800
@@ -21,12 +21,15 @@
variable_set('cache_flush', 0);
}
- $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {". $table ."} WHERE cid = '%s'", $key));
+ $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $key));
if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data.
if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
// If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the
@@ -40,6 +43,9 @@
}
else {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
}
return $cache;
@@ -78,8 +84,8 @@
* The table $table to store the data in. Valid core values are 'cache_filter',
* 'cache_menu', 'cache_page', or 'cache'.
* @param $data
- * The data to store in the cache. Complex data types must be serialized first.
- * @param $expire
+ * The data to store in the cache. Complex data types will be automatically serialized before insertion.
+ * Strings will be stored as plain text and not serialized. * @param $expire
* One of the following values:
* - CACHE_PERMANENT: Indicates that the item should never be removed unless
* explicitly told to using cache_clear_all() with a cache ID.
@@ -91,10 +97,15 @@
* A string containing HTTP header information for cached pages.
*/
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
+ $serialized = 0;
+ if (is_object($data) || is_array($data)) {
+ $data = serialize($data);
+ $serialized = 1;
+ }
db_lock_table($table);
- db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
+ db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid);
if (!db_affected_rows()) {
- @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
+ @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized);
}
db_unlock_tables();
}
@@ -164,4 +175,3 @@
}
}
}
-
diff -ur includes/menu.inc includes/menu.inc
--- includes/menu.inc 2007-06-16 18:50:50.000000000 -0700
+++ includes/menu.inc 2008-01-29 13:56:55.000000000 -0800
@@ -208,12 +208,12 @@
$cid = "$user->uid:$locale";
if ($cached = cache_get($cid, 'cache_menu')) {
- $_menu = unserialize($cached->data);
+ $_menu = $cached->data;
}
else {
_menu_build();
// Cache the menu structure for this user, to expire after one day.
- cache_set($cid, 'cache_menu', serialize($_menu), time() + (60 * 60 * 24));
+ cache_set($cid, 'cache_menu', $_menu, time() + (60 * 60 * 24));
}
// Make sure items that cannot be cached are added.
diff -ur modules/locale/locale.module modules/locale/locale.module
--- modules/locale/locale.module 2006-12-27 05:11:59.000000000 -0800
+++ modules/locale/locale.module 2008-01-29 13:56:55.000000000 -0800
@@ -172,7 +172,7 @@
locale_refresh_cache();
$cache = cache_get("locale:$locale", 'cache');
}
- $locale_t = unserialize($cache->data);
+ $locale_t = $cache->data;
}
// We have the translation cached (if it is TRUE, then there is no
@@ -231,7 +231,7 @@
while ($data = db_fetch_object($result)) {
$t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
}
- cache_set("locale:$locale", 'cache', serialize($t));
+ cache_set("locale:$locale", 'cache', $t);
}
}
diff -ur includes/bootstrap.inc includes/bootstrap.inc
--- includes/bootstrap.inc 2007-07-26 12:16:45.000000000 -0700
+++ includes/bootstrap.inc 2008-01-29 13:54:46.000000000 -0800
@@ -382,14 +382,14 @@
function variable_init($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
if ($cached = cache_get('variables', 'cache')) {
- $variables = unserialize($cached->data);
+ $variables = $cached->data;
}
else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
- cache_set('variables', 'cache', serialize($variables));
+ cache_set('variables', 'cache', $variables);
}
foreach ($conf as $name => $value) {
Only in includes: bootstrap.inc.orig
diff -ur includes/cache.inc includes/cache.inc
--- includes/cache.inc 2007-06-26 20:35:48.000000000 -0700
+++ includes/cache.inc 2008-01-29 13:54:46.000000000 -0800
@@ -21,12 +21,15 @@
variable_set('cache_flush', 0);
}
- $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {". $table ."} WHERE cid = '%s'", $key));
+ $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $key));
if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data.
if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
// If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the
@@ -40,6 +43,9 @@
}
else {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
}
return $cache;
@@ -78,8 +84,8 @@
* The table $table to store the data in. Valid core values are 'cache_filter',
* 'cache_menu', 'cache_page', or 'cache'.
* @param $data
- * The data to store in the cache. Complex data types must be serialized first.
- * @param $expire
+ * The data to store in the cache. Complex data types will be automatically serialized before insertion.
+ * Strings will be stored as plain text and not serialized. * @param $expire
* One of the following values:
* - CACHE_PERMANENT: Indicates that the item should never be removed unless
* explicitly told to using cache_clear_all() with a cache ID.
@@ -91,10 +97,15 @@
* A string containing HTTP header information for cached pages.
*/
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
+ $serialized = 0;
+ if (is_object($data) || is_array($data)) {
+ $data = serialize($data);
+ $serialized = 1;
+ }
db_lock_table($table);
- db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
+ db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid);
if (!db_affected_rows()) {
- @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
+ @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized);
}
db_unlock_tables();
}
@@ -164,4 +175,3 @@
}
}
}
-
diff -ur includes/menu.inc includes/menu.inc
--- includes/menu.inc 2007-06-16 18:50:50.000000000 -0700
+++ includes/menu.inc 2008-01-29 13:54:46.000000000 -0800
@@ -208,12 +208,12 @@
$cid = "$user->uid:$locale";
if ($cached = cache_get($cid, 'cache_menu')) {
- $_menu = unserialize($cached->data);
+ $_menu = $cached->data;
}
else {
_menu_build();
// Cache the menu structure for this user, to expire after one day.
- cache_set($cid, 'cache_menu', serialize($_menu), time() + (60 * 60 * 24));
+ cache_set($cid, 'cache_menu', $_menu, time() + (60 * 60 * 24));
}
// Make sure items that cannot be cached are added.
diff -ur modules/locale/locale.module modules/locale/locale.module
--- modules/locale/locale.module 2006-12-27 05:11:59.000000000 -0800
+++ modules/locale/locale.module 2008-01-29 13:54:46.000000000 -0800
@@ -172,7 +172,7 @@
locale_refresh_cache();
$cache = cache_get("locale:$locale", 'cache');
}
- $locale_t = unserialize($cache->data);
+ $locale_t = $cache->data;
}
// We have the translation cached (if it is TRUE, then there is no
@@ -231,7 +231,7 @@
while ($data = db_fetch_object($result)) {
$t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
}
- cache_set("locale:$locale", 'cache', serialize($t));
+ cache_set("locale:$locale", 'cache', $t);
}
}
diff -ur includes/bootstrap.inc includes/bootstrap.inc
--- includes/bootstrap.inc 2007-10-27 21:53:14.000000000 -0700
+++ includes/bootstrap.inc 2008-01-29 13:58:30.000000000 -0800
@@ -382,14 +382,14 @@
function variable_init($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
if ($cached = cache_get('variables', 'cache')) {
- $variables = unserialize($cached->data);
+ $variables = $cached->data;
}
else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
- cache_set('variables', 'cache', serialize($variables));
+ cache_set('variables', 'cache', $variables);
}
foreach ($conf as $name => $value) {
Only in includes: bootstrap.inc.orig
diff -ur includes/cache.inc includes/cache.inc
--- includes/cache.inc 2007-06-26 20:35:48.000000000 -0700
+++ includes/cache.inc 2008-01-29 13:58:30.000000000 -0800
@@ -21,12 +21,15 @@
variable_set('cache_flush', 0);
}
- $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {". $table ."} WHERE cid = '%s'", $key));
+ $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $key));
if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data.
if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
// If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the
@@ -40,6 +43,9 @@
}
else {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
}
return $cache;
@@ -78,8 +84,8 @@
* The table $table to store the data in. Valid core values are 'cache_filter',
* 'cache_menu', 'cache_page', or 'cache'.
* @param $data
- * The data to store in the cache. Complex data types must be serialized first.
- * @param $expire
+ * The data to store in the cache. Complex data types will be automatically serialized before insertion.
+ * Strings will be stored as plain text and not serialized. * @param $expire
* One of the following values:
* - CACHE_PERMANENT: Indicates that the item should never be removed unless
* explicitly told to using cache_clear_all() with a cache ID.
@@ -91,10 +97,15 @@
* A string containing HTTP header information for cached pages.
*/
function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
+ $serialized = 0;
+ if (is_object($data) || is_array($data)) {
+ $data = serialize($data);
+ $serialized = 1;
+ }
db_lock_table($table);
- db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
+ db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid);
if (!db_affected_rows()) {
- @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
+ @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized);
}
db_unlock_tables();
}
@@ -164,4 +175,3 @@
}
}
}
-
diff -ur includes/menu.inc includes/menu.inc
--- includes/menu.inc 2007-06-16 18:50:50.000000000 -0700
+++ includes/menu.inc 2008-01-29 13:58:30.000000000 -0800
@@ -208,12 +208,12 @@
$cid = "$user->uid:$locale";
if ($cached = cache_get($cid, 'cache_menu')) {
- $_menu = unserialize($cached->data);
+ $_menu = $cached->data;
}
else {
_menu_build();
// Cache the menu structure for this user, to expire after one day.
- cache_set($cid, 'cache_menu', serialize($_menu), time() + (60 * 60 * 24));
+ cache_set($cid, 'cache_menu', $_menu, time() + (60 * 60 * 24));
}
// Make sure items that cannot be cached are added.
diff -ur modules/locale/locale.module modules/locale/locale.module
--- modules/locale/locale.module 2006-12-27 05:11:59.000000000 -0800
+++ modules/locale/locale.module 2008-01-29 13:58:30.000000000 -0800
@@ -172,7 +172,7 @@
locale_refresh_cache();
$cache = cache_get("locale:$locale", 'cache');
}
- $locale_t = unserialize($cache->data);
+ $locale_t = $cache->data;
}
// We have the translation cached (if it is TRUE, then there is no
@@ -231,7 +231,7 @@
while ($data = db_fetch_object($result)) {
$t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
}
- cache_set("locale:$locale", 'cache', serialize($t));
+ cache_set("locale:$locale", 'cache', $t);
}
}
diff -ur includes/bootstrap.inc includes/bootstrap.inc
--- includes/bootstrap.inc 2007-10-27 21:53:14.000000000 -0700
+++ includes/bootstrap.inc 2008-01-29 13:59:54.000000000 -0800
@@ -382,14 +382,14 @@
function variable_init($conf = array()) {
// NOTE: caching the variables improves performance by 20% when serving cached pages.
if ($cached = cache_get('variables', 'cache')) {
- $variables = unserialize($cached->data);
+ $variables = $cached->data;
}
else {
$result = db_query('SELECT * FROM {variable}');
while ($variable = db_fetch_object($result)) {
$variables[$variable->name] = unserialize($variable->value);
}
- cache_set('variables', 'cache', serialize($variables));
+ cache_set('variables', 'cache', $variables);
}
foreach ($conf as $name => $value) {
Only in includes: bootstrap.inc.orig
diff -ur includes/cache.inc includes/cache.inc
--- includes/cache.inc 2007-06-26 20:35:48.000000000 -0700
+++ includes/cache.inc 2008-01-29 13:59:54.000000000 -0800
@@ -21,12 +21,15 @@
variable_set('cache_flush', 0);
}
- $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {". $table ."} WHERE cid = '%s'", $key));
+ $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $key));
if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data.
if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
// If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the
@@ -40,6 +43,9 @@
}
else {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
}
return $cache;
@@ -78,8 +84,8 @@
* The table $table to store the data in. Valid core values are 'cache_filter',
* 'cache_menu', 'cache_page', or 'cache'.
* @param $data
- * The data to store in the cache. Complex data types must be serialized first.
- * @param $expire
+ * The data to store in the cache. Complex data types will be automatically serialized before insertion.