Skip to content
Snippets Groups Projects
Commit f0b98e47 authored by Earl Miles's avatar Earl Miles
Browse files

Cleanup old object cache on cron

parent 19287936
No related branches found
No related tags found
No related merge requests found
...@@ -146,3 +146,15 @@ function ctools_access_menu($access) { ...@@ -146,3 +146,15 @@ function ctools_access_menu($access) {
ctools_include('context'); ctools_include('context');
return ctools_access($access, $contexts); return ctools_access($access, $contexts);
} }
/**
* Implementation of hook_cron. Clean up old caches.
*/
function ctools_cron() {
if (variable_get('ctools_last_cron', 0) < time() - 86400) {
variable_set('ctools_last_cron', time());
ctools_include('object-cache');
ctools_object_cache_cron();
}
}
...@@ -120,3 +120,11 @@ function ctools_object_cache_clean($age = NULL) { ...@@ -120,3 +120,11 @@ function ctools_object_cache_clean($age = NULL) {
function ctools_object_cache_test($obj, $name) { function ctools_object_cache_test($obj, $name) {
return db_fetch_object(db_query("SELECT s.uid, c.updated FROM {ctools_object_cache} c INNER JOIN {sessions} s ON c.sid = s.sid WHERE s.sid != '%s' AND c.obj = '%s' AND c.name = '%s' ORDER BY c.updated ASC", session_id(), $obj, $name)); return db_fetch_object(db_query("SELECT s.uid, c.updated FROM {ctools_object_cache} c INNER JOIN {sessions} s ON c.sid = s.sid WHERE s.sid != '%s' AND c.obj = '%s' AND c.name = '%s' ORDER BY c.updated ASC", session_id(), $obj, $name));
} }
/**
* Clean up old cached items on cron.
*/
function ctools_object_cache_cron() {
// delete anything 7 days old or more.
db_query("DELETE FROM {ctools_object_cache} WHERE timestamp < %d", time() - (86400 * 7));
}
...@@ -42,7 +42,7 @@ function ctools_context_create_user($empty, $data = NULL, $conf = FALSE) { ...@@ -42,7 +42,7 @@ function ctools_context_create_user($empty, $data = NULL, $conf = FALSE) {
if (!empty($data)) { if (!empty($data)) {
$context->data = $data; $context->data = $data;
$context->title = $data->name; $context->title = isset($data->name) ? $data->name : t('Anonymous');
$context->argument = $data->uid; $context->argument = $data->uid;
return $context; return $context;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment