function file_entity_invalidate_field_caches in File Entity (fieldable files) 7.2
Same name and namespace in other branches
- 7.3 file_entity.module \file_entity_invalidate_field_caches()
Clear the field cache for any entities referencing a specific file.
Parameters
object $file: A file object.
3 calls to file_entity_invalidate_field_caches()
- file_entity_file_delete in ./
file_entity.file.inc - Implements hook_file_delete().
- file_entity_file_insert in ./
file_entity.file.inc - Implements hook_file_insert().
- file_entity_file_update in ./
file_entity.file.inc - Implements hook_file_update().
File
- ./
file_entity.module, line 2272 - Extends Drupal file entities to be fieldable and viewable.
Code
function file_entity_invalidate_field_caches($file) {
$entity_types =& drupal_static(__FUNCTION__);
// Gather the list of entity types which support field caching.
if (!isset($entity_types)) {
$entity_types = array();
foreach (entity_get_info() as $entity_type => $entity_info) {
if (!empty($entity_info['fieldable']) && !empty($entity_info['field cache'])) {
$entity_types[] = $entity_type;
}
}
}
// If no entity types support field caching, then there is no work to be done.
if (empty($entity_types)) {
return;
}
$records = db_query("SELECT DISTINCT type, id FROM {file_usage} WHERE fid = :fid AND type IN (:types) AND id > 0", array(
':fid' => $file->fid,
':types' => $entity_types,
))
->fetchAll();
if (!empty($records)) {
$cids = array();
foreach ($records as $record) {
$cids[] = 'field:' . $record->type . ':' . $record->id;
}
cache_clear_all($cids, 'cache_field');
}
}