/[drupal]/contributions/modules/memcache/patches/DRUPAL-5-6-cache-serialize.patch
ViewVC logotype

Contents of /contributions/modules/memcache/patches/DRUPAL-5-6-cache-serialize.patch

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Tue Jan 29 22:50:25 2008 UTC (21 months, 4 weeks ago) by slantview
Branch: MAIN
CVS Tags: HEAD
Branch point for: DRUPAL-5
File MIME type: text/x-patch
Cleanup work:
  * Fixed SQL Error in memcache.db.inc
  * Added CACHE_TEMPORARY memcache caching to memcache.db.inc (full page cache and other things weren't going in)
  * Small code cleanup in memcache.db.inc
  * Changed MENU_DEFAULT_LOCAL_TASK to MENU_LOCAL_TASK in memcache_admin.module
  * Updated README.txt for memcache-session.inc

Added:
  * patches directory to hold all of the patches
  * Drupal 5.0 - 5.6 patches for core

Removed:
  * Old core serialization patch that only "kinda" applied to certain versions. Should be easier
    to know which version to use now.
1 diff -ur includes/bootstrap.inc includes/bootstrap.inc
2 --- includes/bootstrap.inc 2008-01-10 14:14:24.000000000 -0800
3 +++ includes/bootstrap.inc 2008-01-29 13:49:38.000000000 -0800
4 @@ -382,14 +382,14 @@
5 function variable_init($conf = array()) {
6 // NOTE: caching the variables improves performance by 20% when serving cached pages.
7 if ($cached = cache_get('variables', 'cache')) {
8 - $variables = unserialize($cached->data);
9 + $variables = $cached->data;
10 }
11 else {
12 $result = db_query('SELECT * FROM {variable}');
13 while ($variable = db_fetch_object($result)) {
14 $variables[$variable->name] = unserialize($variable->value);
15 }
16 - cache_set('variables', 'cache', serialize($variables));
17 + cache_set('variables', 'cache', $variables);
18 }
19
20 foreach ($conf as $name => $value) {
21 Only in includes: bootstrap.inc.orig
22 diff -ur includes/cache.inc includes/cache.inc
23 --- includes/cache.inc 2007-06-26 20:35:48.000000000 -0700
24 +++ includes/cache.inc 2008-01-29 13:49:38.000000000 -0800
25 @@ -21,12 +21,15 @@
26 variable_set('cache_flush', 0);
27 }
28
29 - $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {". $table ."} WHERE cid = '%s'", $key));
30 + $cache = db_fetch_object(db_query("SELECT data, created, headers, expire, serialized FROM {". $table ."} WHERE cid = '%s'", $key));
31 if (isset($cache->data)) {
32 // If the data is permanent or we're not enforcing a minimum cache lifetime
33 // always return the cached data.
34 if ($cache->expire == CACHE_PERMANENT || !variable_get('cache_lifetime', 0)) {
35 $cache->data = db_decode_blob($cache->data);
36 + if ($cache->serialized) {
37 + $cache->data = unserialize($cache->data);
38 + }
39 }
40 // If enforcing a minimum cache lifetime, validate that the data is
41 // currently valid for this user before we return it by making sure the
42 @@ -40,6 +43,9 @@
43 }
44 else {
45 $cache->data = db_decode_blob($cache->data);
46 + if ($cache->serialized) {
47 + $cache->data = unserialize($cache->data);
48 + }
49 }
50 }
51 return $cache;
52 @@ -78,8 +84,8 @@
53 * The table $table to store the data in. Valid core values are 'cache_filter',
54 * 'cache_menu', 'cache_page', or 'cache'.
55 * @param $data
56 - * The data to store in the cache. Complex data types must be serialized first.
57 - * @param $expire
58 + * The data to store in the cache. Complex data types will be automatically serialized before insertion.
59 + * Strings will be stored as plain text and not serialized. * @param $expire
60 * One of the following values:
61 * - CACHE_PERMANENT: Indicates that the item should never be removed unless
62 * explicitly told to using cache_clear_all() with a cache ID.
63 @@ -91,10 +97,15 @@
64 * A string containing HTTP header information for cached pages.
65 */
66 function cache_set($cid, $table = 'cache', $data, $expire = CACHE_PERMANENT, $headers = NULL) {
67 + $serialized = 0;
68 + if (is_object($data) || is_array($data)) {
69 + $data = serialize($data);
70 + $serialized = 1;
71 + }
72 db_lock_table($table);
73 - db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s' WHERE cid = '%s'", $data, time(), $expire, $headers, $cid);
74 + db_query("UPDATE {". $table. "} SET data = %b, created = %d, expire = %d, headers = '%s', serialized = %d WHERE cid = '%s'", $data, time(), $expire, $headers, $serialized, $cid);
75 if (!db_affected_rows()) {
76 - @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers) VALUES ('%s', %b, %d, %d, '%s')", $cid, $data, time(), $expire, $headers);
77 + @db_query("INSERT INTO {". $table. "} (cid, data, created, expire, headers, serialized) VALUES ('%s', %b, %d, %d, '%s', %d)", $cid, $data, time(), $expire, $headers, $serialized);
78 }
79 db_unlock_tables();
80 }
81 @@ -164,4 +175,3 @@
82 }
83 }
84 }
85 -
86 diff -ur includes/menu.inc includes/menu.inc
87 --- includes/menu.inc 2007-06-16 18:50:50.000000000 -0700
88 +++ includes/menu.inc 2008-01-29 13:49:38.000000000 -0800
89 @@ -208,12 +208,12 @@
90
91 $cid = "$user->uid:$locale";
92 if ($cached = cache_get($cid, 'cache_menu')) {
93 - $_menu = unserialize($cached->data);
94 + $_menu = $cached->data;
95 }
96 else {
97 _menu_build();
98 // Cache the menu structure for this user, to expire after one day.
99 - cache_set($cid, 'cache_menu', serialize($_menu), time() + (60 * 60 * 24));
100 + cache_set($cid, 'cache_menu', $_menu, time() + (60 * 60 * 24));
101 }
102
103 // Make sure items that cannot be cached are added.
104 diff -ur modules/locale/locale.module modules/locale/locale.module
105 --- modules/locale/locale.module 2006-12-27 05:11:59.000000000 -0800
106 +++ modules/locale/locale.module 2008-01-29 13:49:38.000000000 -0800
107 @@ -172,7 +172,7 @@
108 locale_refresh_cache();
109 $cache = cache_get("locale:$locale", 'cache');
110 }
111 - $locale_t = unserialize($cache->data);
112 + $locale_t = $cache->data;
113 }
114
115 // We have the translation cached (if it is TRUE, then there is no
116 @@ -231,7 +231,7 @@
117 while ($data = db_fetch_object($result)) {
118 $t[$data->source] = (empty($data->translation) ? TRUE : $data->translation);
119 }
120 - cache_set("locale:$locale", 'cache', serialize($t));
121 + cache_set("locale:$locale", 'cache', $t);
122 }
123 }
124

  ViewVC Help
Powered by ViewVC 1.1.2