i am deleting from the database using the following code. and when i go to the user page the field still filled. after clearing the cache the changes applied.
i have tried user_save() and user_load() just after executing the sql query.
$num_deleted = db_delete('field_data_field_teams')
->condition('field_teams_tid', $mytid)
->condition('entity_id', $user_fields->uid)
->condition('entity_type', 'user')
->execute();
$account = user_load($uid);
user_save($account);
i want the changes to be applied instantly.
You just need to reset the cache data for this specific user entity. The straightest way to achieve that is to use DrupalEntityControllerInterface ::resetCache()
method :
entity_get_controller('user')->resetCache(array($uid));
Depending on how is managed your field and if it's "attached" or not, you might also need to clear the field cache data :
cache_clear_all('field:user:' . $uid, 'cache_field', TRUE);
Other functions are just too heavy for that tasks and are definitely not what you want :
cache_clear_all()
expires data from all (or a subset of) cache_*
tables. drupal_flush_all_caches()
does the same as the function above, but in addition it rebuilds the menu cache and the theme registries, the entity and node type info arrays, it also clear the css and js caches, and finally it invokes hooks so that other modules' cache data can be cleared as well. Note : If your goal was just to clear the field cache data following a field data deletion, consider using the function field_purge_data()
- that will purge both field data and field cache - instead of performing database operation on the field thus resulting in invalid cache data.