diff --git a/boost.module b/boost.module index 3c77748d75387ee1c3ae18ed204a7d55be686271..fb51bf64742476a75f0f24c0a933e5fe8bee5c25 100644 --- a/boost.module +++ b/boost.module @@ -33,7 +33,7 @@ define('BOOST_ROOT_FILE', variable_get('boost_root_file', '.boost')); define('BOOST_FLUSH_DIR', variable_get('boost_flush_dir', TRUE)); define('BOOST_MAX_PATH_DEPTH', 10); -// Cacheing Options +// Caching Options define('BOOST_CACHE_XML', variable_get('boost_cache_xml', FALSE)); define('BOOST_CACHE_JSON', variable_get('boost_cache_json', FALSE)); define('BOOST_CACHE_HTML', variable_get('boost_cache_html', TRUE)); @@ -452,7 +452,7 @@ function boost_expire_node($node) { if ($node->promote == 1) { boost_cache_expire_derivative(''); } - boost_cache_expire_derivative('node/' . $node->nid, TRUE); + boost_cache_expire_derivative('node/' . $node->nid); // Get terms and flush their page if (module_exists('taxonomy') && BOOST_FLUSH_NODE_TERMS) { @@ -481,14 +481,14 @@ function boost_expire_node($node) { } } foreach ($nids as $nid) { - boost_cache_expire_derivative('node/' . $nid, TRUE); + boost_cache_expire_derivative('node/' . $nid); } // Get CCK references pointing to this node and flush. if (module_exists('nodereferrer')) { $nids = nodereferrer_referrers($node->nid); foreach ($nids as $nid) { - boost_cache_expire_derivative('node/' . $nid['nid'], TRUE); + boost_cache_expire_derivative('node/' . $nid['nid']); } } } @@ -688,7 +688,7 @@ function boost_block_flush_form() { } function boost_block_form_flush_submit(&$form_state, $form) { - boost_cache_expire_derivative($form['values']['path'], TRUE); + boost_cache_expire_derivative($form['values']['path']); } function boost_block_db_settings_form() { @@ -1222,73 +1222,73 @@ function boost_cache_delete($flush = FALSE) { * * @param $path * Current URL - * @param $wildcard - * If true get all chached files that start with this path. */ -function boost_cache_expire_derivative($path, $wildcard = FALSE) { +function boost_cache_expire_derivative($path) { global $base_path; - //path alias + $paths = array(); + + // Given path + $paths[] = $path; + + // Path alias $path_alias = url($path, array('absolute' => FALSE)); if ($base_path != '/') { - $path_alias = implode('/', array_diff_assoc(array_filter(explode('/', $path_alias)), array_filter(explode('/', $base_path)))); + $paths[] = implode('/', array_diff_assoc(array_filter(explode('/', $path_alias)), array_filter(explode('/', $base_path)))); } - //path redirects + // Path redirects if (module_exists('path_redirect')) { $path_redirects = boost_path_redirect_load(array('redirect' => $path)); - } - - //flush caches - boost_cache_expire($path_alias, $wildcard); - if (isset($path_redirects)) { - foreach ($path_redirects as $path_redirect) { - boost_cache_expire($path_redirect['path'], $wildcard); + if (isset($path_redirects)) { + foreach ($path_redirects as $path_redirect) { + $paths[] = $path_redirect['path']; + } } } - boost_cache_expire($path, $wildcard); + boost_cache_expire($paths); } /** - * Expires the static file cache for a given page, or multiple pages - * matching a wildcard. + * Expires the static file cache for the given paths * - * @param $path - * Current URL - * @param $wildcard - * If true get all chached files that start with this path. - * - * TODO: Replace glob() with a database operation. + * @param $paths + * Array of URL's */ -function boost_cache_expire($path, $wildcard = FALSE) { - // Sanity check - if (boost_file_path($path, FALSE) === FALSE) { - return FALSE; - } +function boost_cache_expire($paths) { + $hashes = array(); + // Get all cache files directly associated with this path + foreach (array_unique($paths) as $path) { + $html = boost_file_path($path, FALSE, BOOST_FILE_EXTENSION); + if ($html === FALSE) { + continue; + } + $xml = boost_file_path($path, FALSE, BOOST_XML_EXTENSION); + $json = boost_file_path($path, FALSE, BOOST_JSON_EXTENSION); - // Get list of related files - $tempA = glob(boost_file_path($path, FALSE, NULL) . (($wildcard) ? '*' : '') . BOOST_FILE_EXTENSION, GLOB_NOSORT); - $tempB = glob(boost_file_path($path, FALSE, NULL) . (($wildcard) ? '*' : '') . BOOST_XML_EXTENSION, GLOB_NOSORT); - if (!empty($tempA) && !empty($tempB)) { - $filenames = array_filter(array_merge($tempA, $tempB)); - } - elseif (!empty($tempA)) { - $filenames = $tempA; - } - elseif (!empty($tempB)) { - $filenames = $tempB; - } - else { - return FALSE; + // Hash the paths + $hashes[] = md5($html); + $hashes[] = md5($xml); + $hashes[] = md5($json); } - if (empty($filenames)) { - return FALSE; + // Input has been MD5-ed should be ok to do this; do not do if not MD5-ed + $sql = implode("' OR hash = '", array_unique($hashes)); + $result = db_query("SELECT * FROM {boost_cache} WHERE hash = '" . $sql . "'"); + + // Eliminate duplicates + $data = array(); + while ($info = db_fetch_array($result)) { + $hash = $info['page_callback'] . '-' . $info['page_arguments'] . '-' . $info['page_id']; + $data[$hash] = $info; } - // Flush expired files - foreach ($filenames as $filename) { - boost_cache_kill($filename); + // Get filesnames & hash from db + foreach ($data as $dblookup) { + $result = db_query("SELECT filename, hash FROM {boost_cache} WHERE page_callback = '%s' AND page_arguments = '%s' AND page_id = '%s'", $dblookup['page_callback'], $dblookup['page_arguments'], $dblookup['page_id']); + while ($info = db_fetch_array($result)) { + // Flush expired files + boost_cache_kill($info['filename'], $info['hash']); + } } - return TRUE; } /** @@ -2718,8 +2718,8 @@ function boost_crawler_run($expire = -1) { * @param $content_type * string - Content type header. */ -function boost_async_opp($output, $wait = TRUE, $content_type = "text/html", $lenght = 0) { - $lenght = ($length == 0) ? (strlen($output)-1) : $length; +function boost_async_opp($output, $wait = TRUE, $content_type = "text/html", $length = 0) { + $length = ($length == 0) ? (strlen($output)-1) : $length; // Prime php for background operations while (ob_get_level()) { ob_end_clean(); @@ -2733,7 +2733,7 @@ function boost_async_opp($output, $wait = TRUE, $content_type = "text/html", $le header("Expires: Sun, 19 Nov 1978 05:00:00 GMT"); header("Cache-Control: no-cache"); header("Cache-Control: must-revalidate"); - header("Content-Length: " . $lenght); + header("Content-Length: " . $length); header("Connection: close"); print($output); ob_end_flush();