| 1 |
<?php |
<?php |
| 2 |
// $Id: cache.inc,v 1.5.2.4 2007/06/27 03:35:48 drumm Exp $ |
// $Id: cache.inc,v 1.5.2.5 2008/02/10 02:05:00 drumm Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* Return data from the persistent cache. |
* Return data from the persistent cache. |
| 14 |
global $user; |
global $user; |
| 15 |
|
|
| 16 |
// Garbage collection necessary when enforcing a minimum cache lifetime |
// Garbage collection necessary when enforcing a minimum cache lifetime |
| 17 |
$cache_flush = variable_get('cache_flush', 0); |
$cache_flush = variable_get('cache_flush_'. $table, 0); |
| 18 |
if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= time())) { |
if ($cache_flush && ($cache_flush + variable_get('cache_lifetime', 0) <= time())) { |
| 19 |
// Reset the variable immediately to prevent a meltdown in heavy load situations. |
// Reset the variable immediately to prevent a meltdown in heavy load situations. |
| 20 |
variable_set('cache_flush', 0); |
variable_set('cache_flush_'. $table, 0); |
| 21 |
// Time to flush old cache data |
// Time to flush old cache data |
| 22 |
db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush); |
db_query("DELETE FROM {". $table ."} WHERE expire != %d AND expire <= %d", CACHE_PERMANENT, $cache_flush); |
| 23 |
} |
} |
| 134 |
// cached data that was cached before the timestamp. |
// cached data that was cached before the timestamp. |
| 135 |
$user->cache = time(); |
$user->cache = time(); |
| 136 |
|
|
| 137 |
$cache_flush = variable_get('cache_flush', 0); |
$cache_flush = variable_get('cache_flush_'. $table, 0); |
| 138 |
if ($cache_flush == 0) { |
if ($cache_flush == 0) { |
| 139 |
// This is the first request to clear the cache, start a timer. |
// This is the first request to clear the cache, start a timer. |
| 140 |
variable_set('cache_flush', time()); |
variable_set('cache_flush_'. $table, time()); |
| 141 |
} |
} |
| 142 |
else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) { |
else if (time() > ($cache_flush + variable_get('cache_lifetime', 0))) { |
| 143 |
// Clear the cache for everyone, cache_flush_delay seconds have |
// Clear the cache for everyone, cache_lifetime seconds have |
| 144 |
// passed since the first request to clear the cache. |
// passed since the first request to clear the cache. |
| 145 |
db_query("DELETE FROM {". $table. "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time()); |
db_query("DELETE FROM {". $table. "} WHERE expire != %d AND expire < %d", CACHE_PERMANENT, time()); |
| 146 |
variable_set('cache_flush', 0); |
variable_set('cache_flush_'. $table, 0); |
| 147 |
} |
} |
| 148 |
} |
} |
| 149 |
else { |
else { |