drupal entitycache 性能有关问题

drupal entitycache 性能问题

Entity cache 能提高性能, 把drupal 的entity 缓存起来, 但是不能跟memcache 和redis 一起用, 不然一删除一个node, 就会清空所有的缓存

 

Entity cache puts core entities into Drupal's cache API.

Due to the entity loading changes in Drupal 7, no core patches are required.

Don't bother using this module if you're not also going to usehttp://drupal.org/project/memcache or http://drupal.org/project/redis - the purpose of entitycache is to allow queries to be offloaded from the database onto alternative storage. There are minimal, if any, gains from using it with the default database cache.

 

代码如下

 

/**
 * Deletes multiple nodes.
 *
 * @param $nids
 *   An array of node IDs.
 */
function node_delete_multiple($nids) {
  $transaction = db_transaction();
  if (!empty($nids)) {
    $nodes = node_load_multiple($nids, array());

    try {
      foreach ($nodes as $nid => $node) {
        // Call the node-specific callback (if any):
        node_invoke($node, 'delete');
        module_invoke_all('node_delete', $node);
        module_invoke_all('entity_delete', $node, 'node');
        field_attach_delete('node', $node);

        // Remove this node from the search index if needed.
        // This code is implemented in node module rather than in search module,
        // because node module is implementing search module's API, not the other
        // way around.
        if (module_exists('search')) {
          search_reindex($nid, 'node');
        }
      }

      // Delete after calling hooks so that they can query node tables as needed.
      db_delete('node')
        ->condition('nid', $nids, 'IN')
        ->execute();
      db_delete('node_revision')
        ->condition('nid', $nids, 'IN')
        ->execute();
      db_delete('history')
        ->condition('nid', $nids, 'IN')
        ->execute();
      db_delete('node_access')
       ->condition('nid', $nids, 'IN')
       ->execute();
    }
    catch (Exception $e) {
      $transaction->rollback();
      watchdog_exception('node', $e);
      throw $e;
    }

    // Clear the page and block and node_load_multiple caches.
    entity_get_controller('node')->resetCache();
  }
}

 

class EntityCacheControllerHelper extends DrupalDefaultEntityController {

  public static function resetEntityCache($controller, array $ids = NULL) {
    // Reset the persistent cache.
    if (!empty($ids)) {
      cache_clear_all($ids, 'cache_entity_' . $controller->entityType);
    }
    else {
      // Force all cached entries to be deleted.
      cache_clear_all('*', 'cache_entity_' . $controller->entityType, TRUE);
    }

    // Give modules the chance to act on any entity.
    foreach (module_implements('entitycache_reset') as $module) {
      $function = $module . '_entitycache_reset';
      $function($ids, $controller->entityType);
    }
    // Give modules the chance to act on a specific entity type.
    foreach (module_implements('entitycache_' . $controller->entityType . '_reset') as $module) {
      $function = $module . '_entitycache_' . $controller->entityType . '_reset';
      $function($ids);
    }
  }

 

 

entity_get_controller('node')->resetCache();
会清空所有cache