From f0b98e4766a077773edd567345972e8b5907d2a4 Mon Sep 17 00:00:00 2001 From: Earl Miles <merlin@logrus.com> Date: Thu, 15 Jan 2009 20:20:54 +0000 Subject: [PATCH] Cleanup old object cache on cron --- ctools.module | 12 ++++++++++++ includes/object-cache.inc | 8 ++++++++ plugins/contexts/user.inc | 2 +- 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/ctools.module b/ctools.module index 374a10ac..b85995db 100644 --- a/ctools.module +++ b/ctools.module @@ -146,3 +146,15 @@ function ctools_access_menu($access) { ctools_include('context'); 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(); + } +} + diff --git a/includes/object-cache.inc b/includes/object-cache.inc index 1cd4bc4b..493567a6 100644 --- a/includes/object-cache.inc +++ b/includes/object-cache.inc @@ -120,3 +120,11 @@ function ctools_object_cache_clean($age = NULL) { 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)); } + +/** + * 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)); +} diff --git a/plugins/contexts/user.inc b/plugins/contexts/user.inc index 6d2e16f8..7a06f19c 100644 --- a/plugins/contexts/user.inc +++ b/plugins/contexts/user.inc @@ -42,7 +42,7 @@ function ctools_context_create_user($empty, $data = NULL, $conf = FALSE) { if (!empty($data)) { $context->data = $data; - $context->title = $data->name; + $context->title = isset($data->name) ? $data->name : t('Anonymous'); $context->argument = $data->uid; return $context; } -- GitLab