You are here

function hook_entitycache_pre_cache_set_alter in Entity cache 7

Act on entities before storing them into cache.

Parameters

array $entities: Array with entity objects.

string $entity_type:

1 invocation of hook_entitycache_pre_cache_set_alter()
EntityCacheControllerHelper::entityCacheSet in includes/entitycache.entitycachecontrollerhelper.inc

File

./entitycache.api.php, line 74
Hooks provided by the Entity cache module.

Code

function hook_entitycache_pre_cache_set_alter(&$entities, $entity_type) {
  if ($entity_type == 'foo' && some_condition()) {

    // Do not store any entities for 'foo' into cache while some_condition() is
    // active.
    $entities = array();
  }
  if ($entity_type == 'bar') {
    foreach ($entities as $entity) {
      if (isset($entity->old_value)) {

        // Make old_value available when loading from cache.
        $entity->old_value = $entity->value;
        $entity->value = some_function($entity->value);
      }
    }
  }
}