Monday, July 23, 2012

Lighter version of loading fields on an entity

Here is an alternative to entity_load() types (node_load(), taxonomy_term_load() etc.) that is useful if you want to bypass all the calls to hook_entity_load()

If you know the entity id, type and 'bundle', then this could reduce load time:


How do you call this function?

For nodes:


For taxonomy terms:


Caveats:
  • Does not call hook_entity_load() hooks.
  • You can implement a caching strategy based on the modules used. For e.g. when entity cache is used, field_attach_load() does not cache data in 'cache_field'

1 comment:

Unknown said...

You could give a look at http://drupal.org/project/entitycache.
You can play around with EntityCacheDefaultEntityController for your custom entities, and actually which entities needs cache or not.