+static int flush_old_values (int max_age)
+{
+ callback_flush_data_t cfd;
+ size_t k;
+
+ memset (&cfd, 0, sizeof (cfd));
+ /* Pass the current time as user data so that we don't need to call
+ * `time' for each node. */
+ cfd.now = time (NULL);
+ cfd.keys = NULL;
+ cfd.keys_num = 0;
+
+ if (max_age > 0)
+ cfd.abs_timeout = cfd.now - max_age;
+ else
+ cfd.abs_timeout = cfd.now + 1;
+
+ /* `tree_callback_flush' will return the keys of all values that haven't
+ * been touched in the last `config_flush_interval' seconds in `cfd'.
+ * The char*'s in this array point to the same memory as ci->file, so we
+ * don't need to free them separately. */
+ g_tree_foreach (cache_tree, tree_callback_flush, (gpointer) &cfd);
+
+ for (k = 0; k < cfd.keys_num; k++)
+ {
+ cache_item_t *ci;
+
+ /* This must not fail. */
+ ci = (cache_item_t *) g_tree_lookup (cache_tree, cfd.keys[k]);
+ assert (ci != NULL);
+
+ /* If we end up here with values available, something's seriously
+ * messed up. */
+ assert (ci->values_num == 0);
+
+ /* Remove the node from the tree */
+ g_tree_remove (cache_tree, cfd.keys[k]);
+ cfd.keys[k] = NULL;
+
+ /* Now free and clean up `ci'. */
+ free (ci->file);
+ ci->file = NULL;
+ free (ci);
+ ci = NULL;
+ } /* for (k = 0; k < cfd.keys_num; k++) */
+
+ if (cfd.keys != NULL)
+ {
+ free (cfd.keys);
+ cfd.keys = NULL;
+ }
+
+ return (0);
+} /* int flush_old_values */
+