I have a problem with caching. I've set up a menu hook for an URL like /user/USER_ID/some_info
, which automatically receives the entire user object because of the way I set up my menu hook (see below).
The problem I'm facing is that I have all caching modules enabled in Drupal (including EntityCache) and the $usr
variable gets passed from the cache. So naturally if I update a field and save it using field_attach_update
, the data is saved into the DB, but the old data is shown on the form, confusing the admins (the checkbox is checked, even though I just unchecked it, and it's value in the DB is in fact 0).
Is there a way I can disable caching for this particular object ($usr
) in this particular function?
Note: on my local machine where caching is pretty much disabled, it works fine, both the UI and DB get updated.
My menu hook:
$items['user/%user/some_info'] = array(
'title' => 'Some Info',
'description' => 'Edit',
'page callback' => 'mymodule_edit_user',
'page arguments' => array(1),
'access arguments' => array('administer users'),
'file' => 'mymodule.pages.inc',
'type' => MENU_LOCAL_TASK,
'weight' => 8
);
The function that gets executed:
function mymodule_edit_user($usr){
// check if POST and validation here
if(isset($_POST['somefield'])) //checkbox
$usr->field_somefield[LANGUAGE_NONE][0]['value'] = 1;
else
$usr->field_somefield[LANGUAGE_NONE][0]['value'] = 0;
field_attach_update('user', $usr);
}