Support resetting the cache in content_profile_load()

kratib - November 9, 2009 - 20:30
Project:Content Profile
Version:6.x-1.0-beta4
Component:Base module
Category:feature request
Priority:normal
Assigned:Unassigned
Status:active
Description

I am trying to use Content Profile within VBO, with an action to automatically create a new profile node if certain conditions are met. I noticed that content_profile_load returns a NULL profile even if a profile has already been created during the same page request, resulting in duplicate profile nodes. The reason is that a static cache is used, but there is no way to reset the cache. Would it be possible to add a $reset parameter to the function, defaulting to FALSE, to force it to try to load again:

<?php
function content_profile_load($type, $uid, $lang = '', $reset = FALSE) {
  static
$cache = array();

  if (!isset(
$cache[$type][$uid][$lang]) || $reset) {
   
$cache[$type][$uid][$lang] = FALSE;
   
$params = array('type' => $type, 'uid' => $uid);
    if (
$node = node_load($lang ? $params + array('language' => $lang) : $params)) {
     
$cache[$type][$uid][$lang] = $node->nid;
    }
    return
$node;
  }
  return !empty(
$cache[$type][$uid][$lang]) ? node_load($cache[$type][$uid][$lang]) : FALSE;
}
?>

Thanks for your consideration.

 
 

Drupal is a registered trademark of Dries Buytaert.