1

I am trying to figure out how to cache custom entities with Entitycache module. As I know Entitycache module doesn't support custom entites created with Entity API, that's why I'm doing like this:

created cache table for own entity: cache_entity_carroza_user

created own controller, extent EntityCacheDefaultEntityController, implemented EntityAPIControllerInterface:

class CarrozaEntityController extends EntityCacheDefaultEntityController implements EntityAPIControllerInterface {
  ...
}

implemented hook_entity_info, specified entity controller:

$return = array(
  'carroza_user' => array(
    'label' => t('Carroza User'),
    'controller class' => 'CarrozaUserEntityController',
....


if(module_exists('entitycache')) {
  $return['carroza_user']['field cache'] = FALSE;
  $return['carroza_user']['entity cache'] = TRUE;
}

created CarrozaUserEntityController:

class CarrozaUserEntityController extends CarrozaEntityController {
  public function __construct($entityType) {
    parent::__construct($entityType);
  }

  public function resetCache(array $ids = NULL) {
    EntityCacheControllerHelper::resetEntityCache($this, $ids);
    parent::resetCache($ids);
  }

  public function load($ids = array(), $conditions = array()) {
    return EntityCacheControllerHelper::entityCacheLoad($this, $ids, $conditions);
  }


  public function create(array $values = array()) {
    $values += array(
      'carroza_uid' => '',
      'is_new' => TRUE,
      ...
    );

    $carroza_user = parent::create($values);
    return $carroza_user;
  }

  public function save($carroza_user, DatabaseTransaction $transaction = NULL) {
    return parent::save($carroza_user, $transaction);
  }
}

I'm doing everything Entitycache documentation says, but can't see any records in cache_entity_carroza_user table. Am I missing something else?

1 Answer 1

1

entitycache.module and entity.module integrate, so that just just work.

All you need to do is make sure that the cache table for your entity table exists and set the keys in hook_entity_info() as you already do.

Not sure why it doesn't work, but I'd start by removing the custom controller and rely on the default one from entity.module.

1
  • thanks for the response. Yes, it's a little strange, that cache table is always empty, and Entity Cache Loader(drush plugin) is not generating caches for my entities also. But when I debug entityCacheLoad method of EntityCache module, I can see my entities are being loaded. But where EntityModule gets them, is not clear...
    – xurshid29
    Commented Feb 5, 2014 at 12:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.