Permalink
Find file
Fetching contributors…
Cannot retrieve contributors at this time
82 lines (75 sloc) 2.41 KB
<?php // $Id$
/**
* Module: cache_delayed
* Date: 2010-12-15 14:45
* Author: ber
*
* Description:
* Delays cache_clear_all
*
* License:
*
* Copyright (C) 2010 ber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.pro See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
define('CACHE_DELAYED_MAX_PER_RUN', 1000);
/**
* Implementation of hook_menu().
*/
function cache_delayed_menu() {
$items = array();
$items['cache_delayed_remove/%'] = array(
'title' => 'remove cache-items',
'page callback' => 'cache_delayed_remove',
'access callback' => 'cache_delayed_authenticate',
'weight' => 0,
'type' => MENU_CALLBACK,
);
return $items;
}
/** Removes delayed cache-items.
*
* @return
* null.
* @TODO: batchapi? or is that too much overhead?
*/
function cache_delayed_remove() {
module_load_include('inc', 'cache_delayed', 'cache_delayed');
$delta = variable_get('cache_delayed_interval', 600);
$after = time() - $delta;
$res = db_query("SELECT * FROM {cache_delayed} WHERE updated_at >= %d LIMIT %d", $after, CACHE_DELAYED_MAX_PER_RUN);
while ($row = db_fetch_array($res)) {
$qid = (empty($row['qid']) ? NULL : empty($row['qid']));
$table = (empty($row['table']) ? NULL : empty($row['table']));
$wildcard = (empty($row['wildcard']) ? FALSE : empty($row['wildcard']));
cache_clear_all($wildcard, $table, $wildcard);
_cache_delayed_db_delete($row['qid']);
}
exit();
}
/** Checks validity of a secret token.
*
* @param $token String.
* Token to validate. Must be set in $conf array of settings.php
*
* @return
* TRUE if token matches, FALSE if not.
*/
function cache_delayed_authenticate() {
$their_token = arg(1);
$our_token = variable_get('cache_delayed_token', '');
return (empty($our_token) ? FALSE: ($our_token == $their_token));
}