]> git.pld-linux.org Git - packages/drupal.git/blame - drupal-19298-cache.patch
- use SetHandler None, it's at least documented
[packages/drupal.git] / drupal-19298-cache.patch
CommitLineData
e546b554
ER
1--- includes/bootstrap.inc.orig 2005-04-08 09:22:33.000000000 -0500
2+++ includes/bootstrap.inc 2005-04-08 17:43:57.000000000 -0500
3@@ -9,6 +9,10 @@
4 define('CACHE_PERMANENT', 0);
5 define('CACHE_TEMPORARY', -1);
6
7+define('CACHE_DISABLED', 0);
8+define('CACHE_ENABLED_STRICT', 1);
9+define('CACHE_ENABLED_LOOSE', 2);
10+
11 define('WATCHDOG_NOTICE', 0);
12 define('WATCHDOG_WARNING', 1);
13 define('WATCHDOG_ERROR', 2);
14@@ -196,9 +200,37 @@ function variable_del($name) {
15 * The cache ID of the data to retrieve.
16 */
17 function cache_get($key) {
18- $cache = db_fetch_object(db_query("SELECT data, created, headers FROM {cache} WHERE cid = '%s'", $key));
19+ global $user;
20+ $sid = session_id();
21+
22+ // CACHE_ENABLED_LOOSE garbage collection
23+ $cache_flush = variable_get('cache_flush', 0);
24+ if ($cache_flush && ($cache_flush + variable_get('cache_flush_delay', 300) <= time())) {
25+ // time to flush old cache data
26+ db_query("DELETE FROM {cache} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
27+ variable_set('cache_flush', 0);
28+ }
29+
30+ $cache = db_fetch_object(db_query("SELECT data, created, headers, expire FROM {cache} WHERE cid = '%s'", $key));
31 if (isset($cache->data)) {
32- $cache->data = db_decode_blob($cache->data);
33+ // if data is permanent or using strict caching, always return data
34+ if ($cache->expire == CACHE_PERMANENT || variable_get('cache', CACHE_DISABLED) == CACHE_ENABLED_STRICT) {
35+ $cache->data = db_decode_blob($cache->data);
36+ }
37+ /* if using loose caching, validate data is current before we return it by
38+ ** making sure the cache entry was created before the timestamp in the
39+ ** current session's cache timer. The cache variable is already loaded
40+ ** into the $user object by sess_read in session.inc
41+ */
42+ else {
43+ if ($user->cache > $cache->created) {
44+ // this cache data is too old and thus not valid for us, ignore it
45+ return 0;
46+ }
47+ else {
48+ $cache->data = db_decode_blob($cache->data);
49+ }
50+ }
51 return $cache;
52 }
53 return 0;
54@@ -235,16 +267,44 @@ function cache_set($cid, $data, $expire
55 * Expire data from the cache.
56 *
57 * @param $cid
58- * If set, the cache ID to delete. Otherwise, all cache entries that can expire
59- * are deleted.
60+ * If set, the cache ID to delete. Otherwise, all cache entries that can
61+ * expire are deleted.
62 *
63 * @param $wildcard
64 * If set to true, the $cid is treated as a substring to match rather than a
65 * complete ID.
66 */
67 function cache_clear_all($cid = NULL, $wildcard = false) {
68+ global $user;
69+ $sid = session_id();
70+
71 if (empty($cid)) {
72- db_query("DELETE FROM {cache} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
73+ if (variable_get('cache', CACHE_DISABLED) == CACHE_ENABLED_STRICT) {
74+ // strict caching, flush all temporary cache entries
75+ db_query("DELETE FROM {cache} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time());
76+ }
77+ else {
78+ $cache_flush = variable_get('cache_flush', 0);
79+ /* loose caching, only flush temporary cache entries that have been
80+ ** invalidated for more than maximum allowable time.
81+ */
82+ if ($cache_flush && ($cache_flush + variable_get('cache_flush_delay', 300) <= time())) {
83+ /* only flush cache data older than $cache_flush, as newer data may
84+ ** now be valid.
85+ */
86+ db_query("DELETE FROM {cache} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush);
87+ variable_set('cache_flush', 0);
88+ }
89+ /* invalidate temporary cache data only for current user/session. We
90+ ** set $user->cache, which gets saved into the sessions table by
91+ ** sess_write() in session.inc.
92+ */
93+ $user->cache = time();
94+ if (variable_get('cache_flush', 0) == 0) {
95+ // set timestamp to know which cache entries we eventually clear
96+ variable_set('cache_flush', time());
97+ }
98+ }
99 }
100 else {
101 if ($wildcard) {
102--- includes/session.inc.orig 2005-04-08 17:33:12.000000000 -0500
103+++ includes/session.inc 2005-04-08 17:33:38.000000000 -0500
104@@ -45,7 +45,7 @@ function sess_read($key) {
105 function sess_write($key, $value) {
106 global $user;
107
108- db_query("UPDATE {sessions} SET uid = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, $_SERVER["REMOTE_ADDR"], $value, time(), $key);
109+ db_query("UPDATE {sessions} SET uid = %d, cache = %d, hostname = '%s', session = '%s', timestamp = %d WHERE sid = '%s'", $user->uid, $user->cache, $_SERVER["REMOTE_ADDR"], $value, time(), $key);
110
111 return '';
112 }
113--- modules/system.module.orig 2005-04-08 09:16:48.000000000 -0500
114+++ modules/system.module 2005-04-08 09:19:50.000000000 -0500
115@@ -37,7 +37,7 @@ function system_help($section) {
116 <pre> 00 * * * * /home/www/drupal/scripts/cron-lynx.sh</pre>
117 Note that it is essential to access <code>cron.php</code> using a browser on the web site's domain; do not run it using command line PHP and avoid using <code>localhost</code> or <code>127.0.0.1</code> or some of the environment variables will not be set correctly and features may not work as expected.</p>
118 <h3><a id=\"cache\">Cache</a></h3>
119- <p>Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached. In order to reduce server load and save bandwidth, Drupal stores and sends cached pages compressed.</p>", array('%base_url' => $base_url, '%cron-link' => "<a href=\"$base_url/cron.php\">$base_url/cron.php</a>", '%lynx' => 'http://lynx.browser.org', '%wget' => 'http://www.gnu.org/software/wget/wget.html' ));
120+ <p>Drupal has a caching mechanism which stores dynamically generated web pages in a database. By caching a web page, Drupal does not have to create the page each time someone wants to view it, instead it takes only one SQL query to display it, reducing response time and the server's load. Only pages requested by \"anonymous\" users are cached. In order to reduce server load and save bandwidth, Drupal stores and sends cached pages compressed. Drupal supports by strict caching and loose caching. Strict caching immediately deletes cached data as soon as it becomes invalid for any user. Loose caching delays the deletion of cached data to provide better performance for high traffic sites.</p>", array('%base_url' => $base_url, '%cron-link' => "<a href=\"$base_url/cron.php\">$base_url/cron.php</a>", '%lynx' => 'http://lynx.browser.org', '%wget' => 'http://www.gnu.org/software/wget/wget.html' ));
121 case 'admin/modules#description':
122 return t('Handles general site configuration for administrators.');
123 }
124--- database/database.mysql.orig 2005-04-08 09:21:50.000000000 -0500
125+++ database/database.mysql 2005-04-08 09:18:25.000000000 -0500
126@@ -574,6 +574,7 @@
127 sid varchar(32) NOT NULL default '',
128 hostname varchar(128) NOT NULL default '',
129 timestamp int(11) NOT NULL default '0',
130+ cache int(11) NOT NULL default '0',
131 session longtext,
132 KEY uid (uid),
133 PRIMARY KEY (sid),
134--- database/database.pgsql.orig 2005-04-08 09:21:55.000000000 -0500
135+++ database/database.pgsql 2005-04-08 09:18:25.000000000 -0500
136@@ -587,6 +587,7 @@
137 sid varchar(32) NOT NULL default '',
138 hostname varchar(128) NOT NULL default '',
139 timestamp integer NOT NULL default '0',
140+ cache integer NOT NULL default '0',
141 session text,
142 PRIMARY KEY (sid)
143 );
144--- modules/system.module~ 2005-12-20 17:03:28.000000000 +0200
145+++ modules/system.module 2005-12-20 17:04:57.000000000 +0200
146@@ -226,7 +226,7 @@ function system_view_general() {
147 $output .= form_group(t('Error handling'), $group);
148
149 // Caching:
150- $group = form_radios(t('Cache support'), 'cache', variable_get('cache', 0), array(t('Disabled'), t('Enabled')), t('Enable or disable the caching of rendered pages. When caching is enabled, Drupal will flush the cache when required to make sure updates take effect immediately. Check the <a href="%documentation">cache documentation</a> for information on Drupal\'s cache system.', array('%documentation' => url('admin/help/system#cache', NULL, NULL, 'cache'))));
151+ $group = form_radios(t('Cache support'), 'cache', variable_get('cache', CACHE_DISABLED), array(CACHE_DISABLED => t('Disabled'), CACHE_ENABLED_STRICT => t('Strict'), CACHE_ENABLED_LOOSE => t('Loose')), t('Enable or disable the caching of rendered pages. When strict caching is enabled, Drupal will flush the entire cache when required to make sure updates take effect immediately. When loose caching is enabled, Drupal will delay the flushing of the entire cache for several minutes, immediately flushing the cache only for specific users. Loose caching is intended to improve performance on high traffic sites. Check the <a href="%documentation">cache documentation</a> for information on Drupal\'s cache system.', array('%documentation' => url('admin/help', NULL, NULL, 'cache'))));
152
153 $output .= form_group(t('Cache settings'), $group);
154
155--- database/updates.inc~ 2005-12-20 17:03:28.000000000 +0200
156+++ database/updates.inc 2005-12-20 17:07:37.000000000 +0200
157@@ -108,6 +108,7 @@ $sql_updates = array(
158 "2005-04-14" => "update_129",
159 "2005-05-06" => "update_130",
160 "2005-05-07" => "update_131"
161+, "2005-12-20" => "update_132"
162 );
163
164 function update_32() {
165@@ -2394,6 +2395,17 @@ function update_131() {
166 return $ret;
167 }
168
169+function update_132() {
170+ $ret = array();
171+ if ($GLOBALS['db_type'] == 'mysql') {
172+ $ret[] = update_sql("ALTER TABLE sessions ADD cache int(11) NOT NULL default '0' AFTER timestamp");
173+ }
174+ elseif ($GLOBALS['db_type'] == 'pgsql') {
175+ $ret[] = update_sql("ALTER TABLE sessions ADD cache int(11) NOT NULL default '0' AFTER timestamp");
176+ }
177+ return $ret;
178+}
179+
180 function update_sql($sql) {
181 $edit = $_POST["edit"];
182 $result = db_query($sql);
This page took 0.045861 seconds and 4 git commands to generate.