Commit 21c15b65 authored by fago's avatar fago

#1111120 patch by jamsilver, fago: support entity cache module.

parent f0728d1f
......@@ -131,6 +131,11 @@
* - form callback: (optional) Specfiy a callback that returns a fully built
* edit form for your entity type. See entity_form().
* In case the 'admin ui' is used, no callback needs to be specified.
* - entity cache: (optional) Whether entities should be cached using the cache
* system. Requires the entitycache module to be installed and enabled. As
* cached entities are only retrieved by id key, the cache would not apply to
* exportable entities retrieved by name key. If enabled, 'field cache' is
* obsolete and should be disabled. Defaults to FALSE.
*
* @see hook_entity_info()
* @see entity_metadata_hook_entity_info()
......
......@@ -192,6 +192,20 @@ class EntityAPIController extends DrupalDefaultEntityController implements Entit
}
}
// Support the entitycache module if activated.
if (!empty($this->entityInfo['entity cache']) && !$revision_id && $ids && !$conditions) {
$cached_entities = EntityCacheControllerHelper::entityCacheGet($this, $ids, $conditions);
// If any entities were loaded, remove them from the ids still to load.
$ids = array_diff($ids, array_keys($cached_entities));
$entities += $cached_entities;
// Add loaded entities to the static cache if we are not loading a
// revision.
if ($this->cache && !empty($cached_entities) && !$revision_id) {
$this->cacheSet($cached_entities);
}
}
// Load any remaining entities from the database. This is the case if $ids
// is set to FALSE (so we load all entities), if there are any ids left to
// load or if loading a revision.
......@@ -231,6 +245,12 @@ class EntityAPIController extends DrupalDefaultEntityController implements Entit
$entities += $queried_entities;
}
// Entitycache module support: Add entities to the entity cache if we are
// not loading a revision.
if (!empty($this->entityInfo['entity cache']) && !empty($queried_entities) && !$revision_id) {
EntityCacheControllerHelper::entityCacheSet($this, $queried_entities);
}
if ($this->cache) {
// Add entities to the cache if we are not loading a revision.
if (!empty($queried_entities) && !$revision_id) {
......@@ -256,6 +276,10 @@ class EntityAPIController extends DrupalDefaultEntityController implements Entit
public function resetCache(array $ids = NULL) {
$this->cacheComplete = FALSE;
parent::resetCache($ids);
// Support the entitycache module.
if (!empty($this->entityInfo['entity cache'])) {
EntityCacheControllerHelper::resetEntityCache($this, $ids);
}
}
/**
......
......@@ -56,6 +56,13 @@ function entity_test_entity_info() {
'label' => $type->label,
);
}
// Support entity cache module.
if (module_exists('entitycache')) {
$return['entity_test']['field cache'] = FALSE;
$return['entity_test']['entity cache'] = TRUE;
}
return $return;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment