Skip to content

Commit

Permalink
Drop caching of rendered HTML; nasty side-effects.
Browse files Browse the repository at this point in the history
Instead, it would be preferable to use Panels’ simple cache of Panes, since that will cause the campaigns to be cached per Panels page instead.
  • Loading branch information
mikl committed Apr 20, 2010
1 parent f2f3f9c commit 8775183
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 25 deletions.
15 changes: 13 additions & 2 deletions ding_campaign.install
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ function ding_campaign_schema() {
),
);

$schema['cache_ding_campaign_rendered'] = drupal_get_schema_unprocessed('system', 'cache');

return $schema;
}

Expand Down Expand Up @@ -155,3 +153,16 @@ function ding_campaign_update_6003(&$sandbox) {
return $ret;
}

/**
* Implementation of hook_update_N().
*
* Create cache table for Ding campaigns.
*/
function ding_campaign_update_6004(&$sandbox) {
$ret = array();

db_drop_table($ret, 'cache_ding_campaign');

return $ret;
}

30 changes: 7 additions & 23 deletions ding_campaign.module
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,6 @@ function ding_campaign_update($node) {
else {
drupal_write_record('ding_campaign', $node, array('nid', 'vid'));
}

// Clear the cached version of the rendered campaign.
// It is not useful to re-render it here, since the theme the campaign
// is displayed in can be different from the one active when this hook
// is invoked, especially when an admin theme is enabled.
cache_clear_all('node_view:' . $node->nid, 'cache_ding_campaign');
}

/**
Expand Down Expand Up @@ -589,8 +583,10 @@ function theme_ding_campaign_rule($element) {
*
* @param array $context
* The context array passed to ding_campaign_get_relevant()
* @param integer $max_count
* The maximum number of campaigns to return.
* @return string
* Rendered campaign nodes, or NULL if no match was found.
* Rendered campaign nodes, or FALSE if no match was found.
* @see ding_campaign_get_relevant().
*/
function theme_ding_campaign_relevant_campaigns($context, $max_count = DING_CAMPAIGN_DEFAULT_COUNT) {
Expand All @@ -599,22 +595,10 @@ function theme_ding_campaign_relevant_campaigns($context, $max_count = DING_CAMP

foreach ($campaigns as $nid) {
if ($nid > 0) {
$cache_key = 'node_view:' . $nid;

// Return data from cache if available.
$cache = ($reset) ? FALSE : cache_get($cache_key, 'cache_ding_campaign');
if ($cache && !empty($cache->data)) {
$output .= $cache->data;
}
else {
$node = node_load($nid);
if ($node && $node->status) {
$rendered_node = node_view($node, TRUE, FALSE, FALSE);
$output .= $rendered_node;

// Cache the rendered output.
cache_set($cache_key, $rendered_node, 'cache_ding_campaign');
}
$node = node_load($nid);
if ($node && $node->status) {
$rendered_node = node_view($node, TRUE, FALSE, FALSE);
$output .= $rendered_node;
}
}
}
Expand Down

0 comments on commit 8775183

Please sign in to comment.