You are here

function entitycache_entity_insert in Entity cache 7

Implements hook_entity_insert().

File

./entitycache.module, line 67
Allows for caching of core entities.

Code

function entitycache_entity_insert($entity, $type) {

  // It is possible for other _insert() hooks to load an entity before it has
  // been properly saved, for example file_field_insert(). This may cause
  // an incomplete entity to be cached, since hooks which run after the one
  // loading the entity do not have a chance to run. Therefore ensure the cache
  // is always cleared when inserting new entities.
  // Since hook_entity_insert() runs last, there's a good chance of acting
  // after other modules are finished loading.
  $info = entity_get_info($type);
  list($id) = entity_extract_ids($type, $entity);
  if (!empty($info['entity cache']) && empty($entity->migrate)) {

    // file_field_insert() no longer exists. Don't take this out
    // just yet though because other modules might also misbehave.
    // cache_clear_all($id, 'cache_entity_' . $type);
  }
}