Entity caching based on the Drupal 7 contrib module has been added to core as an alternative to field caching and to fully cache entities that contain non-field data. This functionality is enabled for the core entity types: nodes, terms, and users.

Entity caching is disabled by default for new entity types, such as those provided by contrib or custom modules. In order to use this on custom entity types, you need to create a cache table, and enable the new "entity cache" key in hook_entity_info().

In your .install file, add the new schema in hook_schema() and hook_update_N();

$cache_schema = backdrop_get_schema_unprocessed('system', 'cache');
$schema['cache_entity_node'] = $cache_schema;
$schema['cache_entity_node']['description'] = "Cache table used to store Node entity records.";

In your .module file, add a new section to the end of hook_entity_info() to set the entity cache entry for each entity type. It is also recommended that you set field cache to FALSE in order to reduce duplication of data in cache tables.

// If the cache table has been created, then enable entity caching on nodes.
if (db_table_exists('cache_entity_node')) {
  $entity_info['node']['entity cache'] = TRUE;
  $entity_info['node']['field cache'] = FALSE;
}

Some entity types provide their own storage controllers. If the DefaultEntityController::load() method is overridden, be sure to call parent::load() to allow the caching system to pull from the entity cache storage.

Take this example from CommentStorageController:

  /**
   * Overrides DefaultEntityController::load().
   */
  public function load($ids = array(), $conditions = array()) {
    $comments = parent::load($ids, $conditions);

    foreach ($comments as $key => $comment) {
      $comment->new = node_mark($comment->nid, $comment->changed);
    }
    return $comments;
  }

The call to parent::load($ids, $conditions) is what pulls the entities from the specified cache table. Additional (non-cached) modifications can be made to the entity after it has been loaded with this approach.

Introduced in branch: 
1.16.x
Introduced in version: 
1.16.0
Impacts: 
Module developers
Related Github Issues: 
https://github.com/backdrop/backdrop-issues/issues/74