Commit 74cf718a by Scott

Delete expired cache button

parent 5af87666
...@@ -160,8 +160,7 @@ class Q2A_Storage_FileCacheDriver ...@@ -160,8 +160,7 @@ class Q2A_Storage_FileCacheDriver
if (is_readable($file)) { if (is_readable($file)) {
$fp = fopen($file, 'r'); $fp = fopen($file, 'r');
$key = fgets($fp); $key = fgets($fp);
$expiry = fgets($fp); $expiry = (int) trim(fgets($fp));
// fclose($fp);
if (is_numeric($expiry) && time() > $expiry) { if (is_numeric($expiry) && time() > $expiry) {
$wasDeleted = $this->deleteFile($file); $wasDeleted = $this->deleteFile($file);
} }
......
...@@ -33,7 +33,7 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) { ...@@ -33,7 +33,7 @@ if (qa_get_logged_in_level() >= QA_USER_LEVEL_ADMIN) {
$state = qa_post_text('state'); $state = qa_post_text('state');
$stoptime = time() + 3; $stoptime = time() + 3;
while (qa_recalc_perform_step($state) && (time() < $stoptime)) while (qa_recalc_perform_step($state) && time() < $stoptime)
; ;
$message = qa_recalc_get_message($state); $message = qa_recalc_get_message($state);
......
...@@ -523,23 +523,23 @@ function qa_recalc_perform_step(&$state) ...@@ -523,23 +523,23 @@ function qa_recalc_perform_step(&$state)
qa_recalc_transition($state, 'doblobstodb_complete'); qa_recalc_transition($state, 'doblobstodb_complete');
break; break;
case 'docachetrim':
qa_recalc_transition($state, 'docachetrim_process');
break;
case 'docacheclear': case 'docacheclear':
qa_recalc_transition($state, 'docacheclear_process'); qa_recalc_transition($state, 'docacheclear_process');
break; break;
case 'docachetrim_process':
case 'docacheclear_process': case 'docacheclear_process':
$cacheDriver = Q2A_Storage_CacheFactory::getCacheDriver(); $cacheDriver = Q2A_Storage_CacheFactory::getCacheDriver();
$cacheStats = $cacheDriver->getStats(); $cacheStats = $cacheDriver->getStats();
$limit = min($cacheStats['files'], 20); $limit = min($cacheStats['files'], 20);
if ($next > $length) { if ($cacheStats['files'] > 0 && $next <= $length) {
qa_recalc_transition($state, 'docacheclear_error'); $deleted = $cacheDriver->clear($limit, $next, ($operation === 'docachetrim_process'));
break;
}
if ($cacheStats['files'] > 0) {
$deleted = $cacheDriver->clear($limit, $next);
$done += $deleted; $done += $deleted;
$next += $limit - $deleted; // if some files were not deleted, skip them next time $next += $limit - $deleted; // skip files that weren't deleted on next iteration
$continue = true; $continue = true;
} else { } else {
qa_recalc_transition($state, 'docacheclear_complete'); qa_recalc_transition($state, 'docacheclear_complete');
...@@ -554,7 +554,7 @@ function qa_recalc_perform_step(&$state) ...@@ -554,7 +554,7 @@ function qa_recalc_perform_step(&$state)
if ($continue) if ($continue)
$state = $operation . "\t" . $length . "\t" . $next . "\t" . $done; $state = $operation . "\t" . $length . "\t" . $next . "\t" . $done;
return $continue && ($done < $length); return $continue && $done < $length;
} }
...@@ -784,11 +784,6 @@ function qa_recalc_get_message($state) ...@@ -784,11 +784,6 @@ function qa_recalc_get_message($state)
$message = qa_recalc_progress_lang('admin/caching_delete_progress', $done, $length); $message = qa_recalc_progress_lang('admin/caching_delete_progress', $done, $length);
break; break;
case 'docacheclear_error':
$message = qa_lang('admin/caching_delete_error');
break;
case 'docachetrim_complete':
case 'docacheclear_complete': case 'docacheclear_complete':
$message = qa_lang('admin/caching_delete_complete'); $message = qa_lang('admin/caching_delete_complete');
break; break;
......
...@@ -56,7 +56,6 @@ return array( ...@@ -56,7 +56,6 @@ return array(
'caching_cleanup' => 'Caching clean-up operations', 'caching_cleanup' => 'Caching clean-up operations',
'caching_delete_all' => 'Delete entire cache', 'caching_delete_all' => 'Delete entire cache',
'caching_delete_complete' => 'Cache successfully deleted', 'caching_delete_complete' => 'Cache successfully deleted',
'caching_delete_error' => 'There was an error deleting some cache files',
'caching_delete_expired' => 'Delete expired cache', 'caching_delete_expired' => 'Delete expired cache',
'caching_delete_progress' => 'Deleted ^1 of ^2 cache files...', 'caching_delete_progress' => 'Deleted ^1 of ^2 cache files...',
'caching_dir_error' => 'The directory ^ defined as QA_CACHE_DIRECTORY is not writable by the web server.', 'caching_dir_error' => 'The directory ^ defined as QA_CACHE_DIRECTORY is not writable by the web server.',
......
...@@ -1815,6 +1815,11 @@ switch ($adminsection) { ...@@ -1815,6 +1815,11 @@ switch ($adminsection) {
), ),
'buttons' => array( 'buttons' => array(
'delete_expired' => array(
'label' => qa_lang_html('admin/caching_delete_expired'),
'tags' => 'name="docachetrim" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'cachetrim_note\');"',
'note' => '<span id="cachetrim_note"></span>',
),
'delete_all' => array( 'delete_all' => array(
'label' => qa_lang_html('admin/caching_delete_all'), 'label' => qa_lang_html('admin/caching_delete_all'),
'tags' => 'name="docacheclear" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'cacheclear_note\');"', 'tags' => 'name="docacheclear" onclick="return qa_recalc_click(this.name, this, ' . qa_js(qa_lang_html('admin/delete_stop')) . ', \'cacheclear_note\');"',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment