summaryrefslogtreecommitdiff
path: root/includes
diff options
context:
space:
mode:
Diffstat (limited to 'includes')
-rw-r--r--includes/bootstrap.inc4
-rw-r--r--includes/cache.inc23
-rw-r--r--includes/theme.inc4
3 files changed, 22 insertions, 9 deletions
diff --git a/includes/bootstrap.inc b/includes/bootstrap.inc
index c4215148f..4d3e8f8e7 100644
--- a/includes/bootstrap.inc
+++ b/includes/bootstrap.inc
@@ -369,14 +369,14 @@ function drupal_get_filename($type, $name, $filename = NULL) {
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', serialize($variables));
+ cache_set('variables', $variables);
}
foreach ($conf as $name => $value) {
diff --git a/includes/cache.inc b/includes/cache.inc
index e7774a10b..4bca5fba8 100644
--- a/includes/cache.inc
+++ b/includes/cache.inc
@@ -2,7 +2,8 @@
// $Id$
/**
- * Return data from the persistent cache.
+ * Return data from the persistent cache. Data may be stored as either plain text or as serialized data.
+ * cache_get will automatically return unserialized objects and arrays.
*
* @param $key
* The cache ID of the data to retrieve.
@@ -21,12 +22,15 @@ function cache_get($key, $table = 'cache') {
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 +44,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;
@@ -75,7 +82,8 @@ function cache_get($key, $table = 'cache') {
* @param $cid
* The cache ID of the data to store.
* @param $data
- * The data to store in the cache. Complex data types must be serialized first.
+ * 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 $table
* The table $table to store the data in. Valid core values are 'cache_filter',
* 'cache_menu', 'cache_page', or 'cache'.
@@ -91,10 +99,15 @@ function cache_get($key, $table = 'cache') {
* A string containing HTTP header information for cached pages.
*/
function cache_set($cid, $data, $table = 'cache', $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();
}
diff --git a/includes/theme.inc b/includes/theme.inc
index f35a64e0e..230bb20da 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -115,7 +115,7 @@ function _theme_set_registry($registry) {
function _theme_load_registry($theme, $theme_engine = NULL) {
$cache = cache_get("theme_registry:$theme", 'cache');
if (isset($cache->data)) {
- $registry = unserialize($cache->data);
+ $registry = $cache->data;
}
else {
$registry = _theme_build_registry($theme, $theme_engine);
@@ -128,7 +128,7 @@ function _theme_load_registry($theme, $theme_engine = NULL) {
* Write the theme_registry cache into the database.
*/
function _theme_save_registry($theme, $registry) {
- cache_set("theme_registry:$theme", serialize($registry));
+ cache_set("theme_registry:$theme", $registry);
}
/**