Commit 4c970c2e authored by robertDouglass's avatar robertDouglass
Browse files

Adding DRUPAL-5-cache-serialze.patch which is a backport of the cache cleanup...

Adding DRUPAL-5-cache-serialze.patch which is a backport of the cache cleanup that has gone into Drupal 6. Updated memcache.inc with the same changes.
parent 4f66bdaa
Index: includes/bootstrap.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/bootstrap.inc,v
retrieving revision 1.145.2.3
diff -u -F^f -r1.145.2.3 bootstrap.inc
--- includes/bootstrap.inc 7 May 2007 04:19:54 -0000 1.145.2.3
+++ includes/bootstrap.inc 10 May 2007 17:45:54 -0000
@@ -339,14 +339,14 @@ function drupal_get_filename($type, $nam
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) {
@@ -849,7 +849,8 @@ function _drupal_bootstrap($phase) {
* 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()) {
Index: includes/cache.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/cache.inc,v
retrieving revision 1.5.2.3
diff -u -F^f -r1.5.2.3 cache.inc
--- includes/cache.inc 22 Apr 2007 23:54:03 -0000 1.5.2.3
+++ includes/cache.inc 10 May 2007 17:45:54 -0000
@@ -21,12 +21,15 @@ function cache_get($key, $table = 'cache
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 @@ function cache_get($key, $table = 'cache
}
else {
$cache->data = db_decode_blob($cache->data);
+ if ($cache->serialized) {
+ $cache->data = unserialize($cache->data);
+ }
}
}
return $cache;
@@ -78,8 +84,8 @@ function cache_get($key, $table = 'cache
* 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 @@ function cache_get($key, $table = 'cache
* 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 @@ function cache_clear_all($cid = NULL, $t
}
}
}
-
Index: includes/menu.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/menu.inc,v
retrieving revision 1.146
diff -u -F^f -r1.146 menu.inc
--- includes/menu.inc 14 Jan 2007 01:37:48 -0000 1.146
+++ includes/menu.inc 10 May 2007 17:45:54 -0000
@@ -208,12 +208,12 @@ function menu_get_menu() {
$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.
Index: modules/locale/locale.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/locale/locale.module,v
retrieving revision 1.155
diff -u -F^f -r1.155 locale.module
--- modules/locale/locale.module 27 Dec 2006 13:11:59 -0000 1.155
+++ modules/locale/locale.module 10 May 2007 17:45:54 -0000
@@ -172,7 +172,7 @@ function locale($string) {
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 @@ function locale_refresh_cache() {
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);
}
}
...@@ -228,12 +228,15 @@ function cache_get($key, $table = 'cache') { ...@@ -228,12 +228,15 @@ function cache_get($key, $table = 'cache') {
} }
// Look for a database cache hit. // Look for a database cache hit.
if ($cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {%s} WHERE cid = '%s'", $table, $key))) { if ($cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {%s} WHERE cid = '%s'", $table, $key))) {
if (isset($cache->data)) { if (isset($cache->data)) {
// If the data is permanent or we're not enforcing a minimum cache lifetime // If the data is permanent or we're not enforcing a minimum cache lifetime
// always return the cached data. // always return the cached data.
if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) { if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
$cache->data = unserialize(db_decode_blob($cache->data)); $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 // If enforcing a minimum cache lifetime, validate that the data is
// currently valid for this user before we return it by making sure the // currently valid for this user before we return it by making sure the
...@@ -246,7 +249,10 @@ function cache_get($key, $table = 'cache') { ...@@ -246,7 +249,10 @@ function cache_get($key, $table = 'cache') {
return 0; return 0;
} }
else { else {
$cache->data = unserialize(db_decode_blob($cache->data)); $cache->data = db_decode_blob($cache->data);
if ($cache->serialized) {
$cache->data = unserialize($cache->data);
}
} }
} }
} }
...@@ -316,11 +322,16 @@ function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $he ...@@ -316,11 +322,16 @@ function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $he
$cache->headers = $headers; $cache->headers = $headers;
if ($db_storage) { if ($db_storage) {
$serialized = 0;
if (is_object($data) || is_array($data)) {
$data = serialize($data);
$serialized = 1;
}
// Save to the database // Save to the database
db_lock_table($table); db_lock_table($table);
db_query("UPDATE {%s} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $table, serialize($data), $cache->created, $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()) { if (!db_affected_rows()) {
@db_query("INSERT INTO {%s} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $table, $cid, serialize($data), $cache->created, $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(); db_unlock_tables();
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment